我有一个名为students
的表,其中包含学生详细信息id,mark,name
我想获得no of students
,no of students passed
(标记可用),no of students failed
低于50的标记失败,超过
是否可以使用3 counts in a single query
获取without
subquery,join or union
?
答案 0 :(得分:1)
像
这样的东西SELECT COUNT(*) TotalStudents,
SUM(CASE WHEN Mark >= 50 THEN 1 ELSE 0 END) TotalPassed,
SUM(CASE WHEN Mark < 50 THEN 1 ELSE 0 END) TotalFailed
FROM students