您好,欢迎访问一九零五行业门户网

mysql 组函数count的具体用法

mysqlcount
select d.department,
count(case e.sex when e.sex='f' and p.position !='主管' then p.id end) fq,
count(case e.sex when e.sex='f' and p.position ='主管' then p.id end) fz,
count(case e.sex when e.sex='m' and p.position !='主管' then p.id end) mq,
count(case e.sex when e.sex='m' and p.position ='主管' then p.id end) mz,
count(e.id) xj
from department d left join employ e on d.id=e.deptid
left join position p on e.positionid=p.id
group by d.id;
出现后面两个count统计不出来是什么原因?
为什么下面个可以查出来?
select d.department,
count(case when e.sex='f' and p.position !='主管' then p.id end) fq,
count(case when e.sex='f' and p.position ='主管' then p.id end) fz,
count(case when e.sex='m' then case when p.position !='主管' then p.id end end) mq
count(case when e.sex='m' then case when p.position ='主管' then p.id end end) mz,
count(e.id) xj
from department d left join employ e on d.id=e.deptid
left join position p on e.positionid=p.id
group by d.id
其它类似信息

推荐信息