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

解决方案 »

  1.   

    select a.部门,count(a.工号) as 人数 ,count(b.员工id) as 请假人数
    from 人事资料表  a join 请假已审核 b
    on a.部门 = b.部门
    where a.离职日期 is null 
    and b. 日期='2010-7-1' 
    group by a.部门
      

  2.   

    没有离职和在'2010-7-1' 请假的
    select 部门,count(工号) as 人数 from 人事资料表 
    where 部门 in
    (select 部门 from 请假已审核 where 日期='2010-7-1')
    and 
    离职日期 is null 
    group by 部门
      

  3.   

    from 人事资料表  a  left  join 请假已审核 b你还是给出你的数据和你需要的结果吧,