user表
user_id | unit_id | user_name | sex |
1 | 4 | 张一 | 男 |
2 | 2 | 张二 | 女 |
3 | 3 |
张三 |
男 |
4 | 4 |
张四 |
女 |
5 | 2 |
张五 |
男 |
6 | 3 |
张六 |
女 |
7 | 2 |
张七 |
男 |
8 | 3 |
张八 |
女 |
unit_id | super_unit_id | unit_name |
1 | 0 | 华迪公司 |
2 | 1 | 财务部 |
3 | 1 | 审计部 |
4 | 1 | 人事部 |
2、查询人员表中,sex都有什么数值,每个数值对应有多少个人。
3、查询人员表中,姓“张”的人员有几个。
-- 1、查询出单位“审计部”下面有几个人员,分别叫什么名称。
select unit_name,GROUP_CONCAT(user_name)人员
from user01,unit
where user01.unit_id=unit.unit_id
GROUP BY unit_name
HAVING unit_name='审计部'
-- 2、查询人员表中,sex都有什么数值,每个数值对应有多少个人。
select sex ,count(1)
from user01
GROUP BY sex
-- 3、查询人员表中,姓“张”的人员有几个。
select left(user_name,1),count(left(user_name,1))
from user01
GROUP BY left(user_name,1)