sum是對內容的數量進行相加,count 對表行數 對象進行統計
在使用 case 時,如
select subject,
count(case when score>80 then score else null end) 優,
count(case when score<80 and score>59 then score else null end) 優,
count(case when score<60 then score else null end) 優
from stuscore group by [subject]
select * from stuscore
select subject,
sum(case when score>80 then score else 1 end) 優,
sum(case when score<80 and score>59 then score else 1end) 優,
sum(case when score<60 then score else 1end) 優
from stuscore group by [subject]
select * from stuscore
這個時候 對sum 進行返回的是1,而對count 返回的是一列(null),或者說是一個行對象進行對數量的統計
