Home > Database > Mysql Tutorial > body text

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

WBOY
Release: 2016-06-06 09:44:53
Original
929 people have browsed it

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语句如下:

<code>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</code>
Copy after login

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

source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template