部门表:
depid depname
1      部门1
2      部门2员工信息表
deployid  empname    
1           姓名1
2           姓名2
3           姓名3
部门员工关系表
depid  deployid
1        1
1        2
2        3考勤表
deployid   date             sbsj
1          2006-10-01       8:40
1          2006-10-02       8:31
2          2006-10-01       8:20
3          2006-10-01       8:40输入部门和月份,统计出某部门在该月份所有员工的迟到情况。研发部:
姓名A:迟到2次
姓名B:迟到1次
如果用JAVA很容易实现,每次统计员工出勤情况后就放入LIST中,最后遍历该部门的LIST即可。
但是这个业务我想通过存储过程来实现,该如何呢?

解决方案 »

  1.   

    select empname, count(*)
    from (
    select *
    from (select deployid, empname, depname
          from 部门表 a, 员工信息表 b, 部门员工关系表 c
          where a.depid(+) = c.depid and b.deployid(+) = c.deployid) x, 考勤表 d
    where x.deployid(+) = d.deployid
    )
    where depname = &dep and trunc(date, 'mm') = to_date(&month, 'mm')
    group by deployid
      

  2.   

    select b.empname,count(b.empname)
      from
    (select d.deployid
      from KAOQINB d
     where trunc(d.date, 'mm') = to_date(&month, 'mm')
       and d.sbsj > '8:30'
    ) x,YUANGONGXINXIB b
     where x.deployid in
    (select c.deployid
      from BUMENB a,BUMENRENYUANGUANXIB c
     where a.depname = &dep
       and c.depid = a.depid
    )
       and b.deployid = x.deployid
     group by b.empname