一张表中, 查询学生及格和不及格人数
[php] view plain copy
- 表结构为:
- ---------------------
- class name score
- 班级 姓名 分数
- 查询每个班级中, 及格和不及格学生的人数
- SELECT `class`,
- SUM(CASE WHEN score>=60 THEN 1 ELSE 0 END) as gt60,
- SUM(CASE WHEN score>=60 THEN 0 ELSE 1 END) as lt60
- FROM tb1
- GROUP BY class
- SELECT class,
- SUM( IF(score >= 60, 1, 0) ) as gt,
- SUM( IF(score < 60, 1, 0 ) ) as lt
- FROM tb1
- GROUP BY class;