专家意见查询是可能的

时间:2011-02-16 12:02:42

标签: mysql

我有一个名为students的表,其中包含学生详细信息id,mark,name

我想获得no of studentsno of students passed(标记可用),no of students failed

低于50的标记失败,超过

是否可以使用3 counts in a single query获取without subquery,join or union

1 个答案:

答案 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