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語句查詢,sql語句查詢

表要告訴我們呀,不要還要我們設計資料庫吧? 給表啊 我想查查這個玩玩 1.select from student 2.select id,name,age from student 我有例題你要嗎 靠 這麼多東西幫你寫不曉得要死多少腦細胞 分還是少了點 這點分。sql語句查詢不等於怎麼查不出來? 大...

sql查詢語句 多重查詢,SQL查詢語句,怎樣查詢重複資料

select count num,systemfrom site visitmessagewhere visit time 2009 07 17 03 20 22 and visit time 2009 07 27 03 20 22 order by num desc select system,c...

模糊查詢Sql語句問題,SQL模糊查詢語句怎麼寫啊

理工愛好者 模糊之後估計效率不太好 如果知道z是開頭字母 select name where pyname like z s 如果zs都是中間字母 select name where pyname like z s 祝好運,望採納。 select from 表面 like zs like是不分大小寫...