-
20200324 连接查询作业
2020-07-24 10:57-- 1、查询张姓员工的员工信息和所在部门信息
SELECT e.
name
,e.leader,e.is_enable,dt.name
as 部门 fromemp
e
left JOIN dept dt on e.dept_id=dt.id
where e.name
like '张%';-- 查询张三丰管理了几个员工
#方法一:
SELECT count(*) from emp ep where ep.leader in(SELECT id from emp where
name
='张三丰');#方法二:
SELECT count(em1.
name
) as 所管理员工数,em2.name
as 领导 from emp em1
LEFT JOIN emp em2 on em1.leader=em2.id
GROUP BY em2.name
having em2.name
='张三丰';-- 查询出所有实习员工(实习员工无部门信息)
SELECT ep.*,dt.
name
as 部门名称 from emp ep
LEFT JOIN dept dt on ep.dept_id=dt.id
where dt.name
is NULL