比如我有一个TeamInfo 表 表数据为
id name title tutortype degree
1 张三 教授 博导 博士
2 李四 副教授 硕导 硕士
3 张四 讲师 硕导 博士
4 张五 讲师 硕士
5 张六 教授 博导 博士
6 张七 讲师 硕导 博士
现在我想统计出下面的形式,分别统计出职称的数据。
职称 人数 博导 硕导 博士学位 硕士学位
教授 2 2 0 2 0
副教授 1 0 1 0 1
讲师 3 0 2 2 1
select title 职称,COUNT(1) 人数,
sum(case when tutortype='博导' then 1 else 0 end) as 博导,
sum(case when tutortype='硕导' then 1 else 0 end) as 硕导,
sum(case when degree='博士' then 1 else 0 end) as 博士,
sum(case when degree='硕士' then 1 else 0 end) as 硕士
from teaminfo
group by title