解决方案 »

  1.   

    select distinct(person_name),c.* from 
    oa_check_out d join
    (select a.person_id,out_times,leave_times,late_times from 
    (select a.person_id,count(*) as out_times from oa_check_out a where status=1 and reason !='WCBS' group by a.person_id) a join 
    (select a.person_id,count(*) as leave_times from oa_check_leave a where status=1 group by a.person_id) b on a.person_id=b.person_id left join
    (select a.person_id,count(*) as late_times from oa_check_out a where status=1 and reason ='WCBS' group by a.person_id) e on
    e.person_id=a.person_id) c on 
    d.person_id=c.person_id
    不好意思哈,哥们。
      

  2.   

    select distinct(person_name),c.* from 
    oa_check_out d join
    (select a.person_id,out_times,leave_times,late_times from 
    (select a.person_id,count(*) as out_times from oa_check_out a where status=1 and reason !='WCBS' group by a.person_id) a join 
    (select a.person_id,count(*) as leave_times from oa_check_leave a where status=1 group by a.person_id) b on a.person_id=b.person_id left join
    (select a.person_id,count(*) as late_times from oa_check_out a where status=1 and reason ='WCBS' group by a.person_id) e on
    e.person_id=a.person_id) c on 
    d.person_id=c.person_id
    不好意思哈,哥们。
      

  3.   

    思路是这样:1.列出所有的外出原因,2利用group 查询请假表中各种原因汇总出来的条数
    再将两个结果关联 就出来了
      

  4.   

    外出原因例就只有'WCBS'这个结果会归出来单独统计。
    用了group就只能像我写的那样去表现其他字段了吗?我这样查询会有数据遗漏吗?
      

  5.   


    select  person_id,
        sum(case when status1=1 and reason !='WCBS' then 1 else 0 end) as out_times,
        sum(case when status2=1 then 1 else 0 end) as leave_times,
        sum(case when status1=1 and reason ='WCBS' then 1 else 0 end) as late_times
    from 
        (
            select person_id,status as status1 ,null as status2, reason from oa_check_out
            union all
            select person_id,null as status1, status as status2, reason from oa_check_leave
        ) un
     group by person_id
    楼主看看这是不是你要的
      

  6.   

    多谢了,确实是这样,不过还是想把person_name这个字段也显示出来。
      

  7.   

    多谢了,确实是这样,不过还是想把person_name这个字段也显示出来。那只要在select和group by 后再加一个字段就可以,记得结贴