select 部门,count(工号) as 人数 from 人事资料表 where 离职日期 is null group by 部门
select 部门,count(员工id) as 请假人数 from 请假已审核 where 日期='2010-7-1' group by 部门
按正常方法是先按条件将2个表连接起来,再分组。
但由于特殊原因,我想直接连起来。不知道怎么连?
select 部门,count(员工id) as 请假人数 from 请假已审核 where 日期='2010-7-1' group by 部门
按正常方法是先按条件将2个表连接起来,再分组。
但由于特殊原因,我想直接连起来。不知道怎么连?
from 人事资料表 a join 请假已审核 b
on a.部门 = b.部门
where a.离职日期 is null
and b. 日期='2010-7-1'
group by a.部门
select 部门,count(工号) as 人数 from 人事资料表
where 部门 in
(select 部门 from 请假已审核 where 日期='2010-7-1')
and
离职日期 is null
group by 部门