如何将groupby结果作为列名
如果我们使用
的话员工表按性别从员工组中选择计数(*);给我一个
但我需要它们作为列男|女|无
答案 0 :(得分:6)
select sum(case when gender = 'Male' then 1 else 0 end) as 'Male',
sum(case when gender = 'Female' then 1 else 0 end) as 'Female',
sum(case when gender not in ('Male','Female') or gender is null then 1 else 0 end) as 'None'
from staff;