有一个mysql表(class),三个字段:id,name,sex,class_id,写一个SQL,统计出每个班级的男生数量和女生数量
select class_id,sex,count(*) from class group by class_id,sex
还有更复杂的:有一个mysql表(score),三个字段:id,name,score,class_id,写一个SQL,统计出每个班级的及格数量和不及格数量
select class_id,cj count(*) from
(select class_id,case when score<60 then “不及格” else “及格” as cj from score)
group by class_id,cj
版权声明:本文为jack_shuai原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。