hc学习平台

 找回密码
 立即注册
搜索
热搜: 活动 交友 javakc
 › zhangjiafu › 日志

根据user表和unit表写出sql语句

2021-01-07 18:51:04 查看(444) 回复(0)

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表

unit_id super_unit_id unit_name
1 0 华迪公司
2 1 财务部
3 1 审计部
4 1 人事部

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)

评论 (0 个评论)

facelist

全部作者的其他最新日志



站点统计|举报|Archiver|手机版|小黑屋|Comsenz Inc.

GMT+8, , Processed in 0.195171 second(s), 9 queries .

Powered by javakc! X1.0

© 2004-2014 javakc

f1208.com 备案号:京ICP备14030918号-1

返回顶部