<--
case "字段" when "条件" then "符合条件的值" else "不符合条件的值" end
!-->
select
dept_id,
sum(case sex when ‘男‘ then 1 else 0 end),
sum(case sex when ‘女‘ then 0 else 1 end)
from
emp_sex
group by dept_id
2024-01-19 09:37:28
<--
case "字段" when "条件" then "符合条件的值" else "不符合条件的值" end
!-->
select
dept_id,
sum(case sex when ‘男‘ then 1 else 0 end),
sum(case sex when ‘女‘ then 0 else 1 end)
from
emp_sex
group by dept_id