天天看點

Mysql面試題:一條SQL語句查詢出每個班的及格人數和不及格人數

用一條SQL語句查詢出每個班的及格人數和不及格人數,格式為:class,及格人數,不及格人數(score>=60為及格)

selet class 班級 
sum(case when score >60 then 1 else 0 end) as 及格人數,
sum(case when socre <60 then 1 else 0 end) as 不及格人數
from score GROUP BY class;

           

更多幹貨關注:

劍指 Offer (3群)