Home  >  Article  >  Database  >  关于mysql数据库查询统计的问题

关于mysql数据库查询统计的问题

WBOY
WBOYOriginal
2016-06-06 09:44:53836browse

mysqlsql查询统计数据库

两张表 eadept,oi_professional

eadept表有两列 deptid(单位代码) deptname(单位名称) ENABLED(是否启用)
oi_profession表 有四列 id(序号) proname(人员姓名) deptid(单位代码) sex(性别)

我想写一个统计sql语句,能查询统计 deptid,deptname,(人员总数量),(女员工数量),(男员工数量)

ps.部门有上下级 例子A部门代码deptid为001,A的下属部门A1部门代码deptid为001001 以此类推

我想让下级部门的人员统计到上级部门

sql语句如下:

SELECT d.deptid, d.DEPTNAME, count(o.deptid) as 总人数, from eadept as d LEFT JOIN oi_professional as o ON o.DEPTID like concat(d.DEPTID,'%') WHERE d.ENABLED=1 GROUP BY d.DEPTID ORDER BY d.DEPTID

我写的只能只能统计总人数,但是男员工 女员工的统计出不来,请大神帮帮看看怎么写~~

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn