emp_list为人员信息表,hiredate为就职日期,firedate为离职日期
select t.dept_code,
0 charges,
0 edcws,
sum((case when t.firedate is null or t.firedate>:ad_end_date then
:ad_end_date
when t.firedate <= :ad_end_date then
t.firedate
end) -
(case when t.hiredate<:ad_start_date then
:ad_start_date
else
t.hiredate
end) +1) total_days,
0 in_hos_days
from emp_list t,dept_dict a
where t.dept_code=a.dept_code
and a.clinic_attr='0' and a.outp_or_inp='1' and a.clinic_flag='2' and a.flag='1'
and (nvl(t.firedate,to_date('9999-12-31','yyyy-mm-dd'))>=:ad_start_date
and t.hiredate<=:ad_end_date)
group by t.dept_code