SQL語句求助,查詢出每門課程及格和不及格的人數

時間 2021-07-13 09:12:52

1樓:管朵景密

用一條語句不好查,本身就是兩個條件,又返回的兩個結果,怎麼用一條語句?

2樓:

select col2,count(col1) as 及格學生人數,(count(*)-count(col1)) as 不及格學生人數

from td

where (col1>='60')

3樓:鱈舞

好難回答你問的問題,,,,,,因為你的表就沒有建好,如何讓人用一條語句就回答並不存在的東西呢。。。~~~~~~~希望你補充一下,然後大家才能幫你呢。。。。。

4樓:匿名使用者

--已經實現行轉列,得到的結果為科目--不及格人數--及格人數declare @tb table (col1 int,col2 int)

insert into @tb

select '50',1

union all

select '79',2

union all

select '58',3

union all

select '67',1

union all

select '95',2

union all

select '35',3

union all

select '48',1

union all

select '87',2

union all

select '66',3

union all

select '55',1

union all

select '77',2

union all

select '59',3

select col2,sum(不及格人數) as 不及格人數,sum(及格人數) as 及格人數

from(

select col2,isnull(case when col1 < 60 then count(*) end,'') as 不及格人數,isnull(case when col1 >= 60 then count(*) end,'') as 及格人數 from

@tbgroup by col2,col1

)tgroup by col2

5樓:隱半戎博耘

select

課程名稱,count(*)

as及格人數

from

成績表where

分數>=

60group

by課程名稱

select

課程名稱,count(*)

as不及格人數

from

成績表where

分數<60group

by課程名稱

6樓:慎燁諾紫薇

表結構什麼樣的啊?及格不及格條件呢?

7樓:

select 課程,flag,count(*)from (

select 課程,分數,case when 分數 >= 60 then '及格' else '不及格' end flag

from table

) tgroup by 課程,flag

8樓:

select * from tb where co1>60 where 課程='語文'

不級格就改為小於號

9樓:

select a.score ,count as 人數 ,col2 as 科目 from

(select case when col1>=60 then '及格' else '不及格' end as score ,col2 from tb g )

a group by a.score,a.col2

10樓:匿名使用者

select col2,count(*) where col1<60 group by col2 --不及格

select col2,count(*) where col1》=60 group by col2 --及格

sql統計每門課程的不及格人數

11樓:庹熙系惜萍

select

學號,課程號,count(*)

as不及格人數

from

scwhere

分數<60

group

by學號,課程號

union

select

'不及格人數','->',sum(count(*))as不及格人數

from

scwhere

分數<60

group

by學號,課程號

order

by不及格人數

12樓:匿名使用者

你的要求有點特別,要求 學號!

如果只是

統計每門課程的不及格人數下面的sql就可以啦:

select cnum,count(cnum) as 不及格人數from sc

where score < 60

group by cnum 注意:是對課程號分組喲,樓上的是錯的。

如果你要輸出學號:

select sc.snum as 學號,a.cnum as 課程號,

a.不及格人數

from sc,

(select cnum,count(cnum) as 不及格人數from sc

where score < 60

group by cnum) as a

where sc.score<60 and sc.cnum=a.cnum

以上我相信是沒有問題的,你測試一下!

如果ok,給分喲呵呵

13樓:匿名使用者

統計每門課程不及格人數,那就根據課程號做分組統計即可,但是輸出時肯定不能輸出學號!學號是針對每個學生的。

select cnum,count(1) from sc where score<60 group by cnum

14樓:匿名使用者

snum,cnum,score < 60 (不及格分數如果是60的話)

15樓:

select snum,cnum

from sc

where score<60

order by score,snum

compute count(snum)

用compute,就可以同時返回學號,課程號,和分數啦……

16樓:閉鯨白俊賢

select

a.score

,count

as人數

,col2

as科目

from

(select

case

when

col1>=60

then

'及格'

else

'不及格'

endas

score

,col2

fromtbg

)agroup

bya.score,a.col2

17樓:匿名使用者

select cnum,count(snum)from sc

where score < 60

group snum

sql語句求助:統計各班每門課程成績均不及格的同學人數

18樓:昂素琴前書

select

a.score

,count

as人數

,col2

as科目

from

(select

case

when

col1>=60

then

'及格'

else

'不及格'

endas

score

,col2

fromtbg

)agroup

bya.score,a.col2

請寫出sql查詢統計每門課程的選修人數顯示課程編號學生人數。

19樓:無怨深淵

sql查詢語句:select 課程編號,count(*) 學生人數 from 課程 group by 選修人數;

ps:sql用於統計

專和分組的函式是:

統計函式:屬

count(*)

分組函式: group by 分組表示式。

sql:

結構化查詢語言,是一種特殊目的的程式語言,是一種資料庫查詢和程式設計語言,用於存取資料以及查詢、更新和管理關聯式資料庫系統;同時也是資料庫指令碼檔案的副檔名。

group by :

從字面意義上理解就是“根據(by)一定的規則進行分組(group)”。它的作用是通過一定的規則將一個資料集劃分成若干個小的區域,然後針對若干個小區域進行資料處理。

20樓:楓葉vs童話

select

c.`daocname`,

count(distinct s.`sno`) as '選修內人數容'

from

score s

right join course c

on s.`cno` = c.`cno`

group by c.`cname`

21樓:匿名使用者

select 成績表.課程編號,count(成績表.課程編號) from 成績表 group by 成績表.課程編號

22樓:匿名使用者

select 課程資訊

表.課程名稱,count(distinct 成績表.學號) from 成績表

join 課程專資訊屬表 on 成績表.課程編號=課程資訊表.課程編group by 課程資訊表.課程名稱

23樓:阿彭

select cno,count(sno)

from sc

group by cno;

24樓:匿名使用者

這個還要問下學校方面

用一條sql語句查詢出「每門」課程都大於80分的學生姓名

首先需要進行分析 要查詢出每門課程都大於80分的學生姓名,因為乙個學生有多門課程,所以會出現下面三種情況。第一可能所有課程都大於80分。第二可能有些課程大於80分,另外一些課程少於80分。第三也可能所有課程都小於80分。那麼我們要查詢出所有大於80分的課程的學生姓名,我們可以反向思考,找出課程小於8...

如何統計sql語句查詢出來的條數

可以通過count函式來實現。sqlone select from tablename1 where id 5 此語句查詢出來多條記錄,之後看做乙個新的表。sqltwo select conut from select from tablename1 where id 5 as tablename2...

急用啊!!SQL語句查詢!!查詢選課門數最多的詳細資訊,包括選選修門數!感謝給位了

你這裡講的選選修門數是不是指間接先修課 先修課的先修課 如果是的話你大可採用自連線的方式把對應先修課的先修課找出來。最後那兩題用分組的思想來做就可以了,就比如說統計每個老師的開課門數,你按老師特有的屬性 如 職工號 來進行分組,然後用count函式進行統計,因為一行表示的就是一門課程。 表結構都沒有...