如上图所示,我现在要求出总共几个人,并且学历为研究生的几个人,本科几个人。
SELECT
COUNT(u.id) as userCount, # 总数
sum(case u.education when '研究生' then 1 else 0 end) as graduateCount, #研究生数量
sum(case u.education when '本科' then 1 else 0 end) as undergraduateCount #本科生数量
FROM
USER u
我们来统计下研究生学历的高级工程师数量:
SELECT
sum(CASE when u.education = "研究生" and u.competent = "高级工程师" then 1 else 0 end) as count
FROM
USER u