如何统计某一时间段内人员的在职天数

该SQL查询从人员信息表emp_list中,根据指定条件(如部门代码、诊所属性等),计算每个部门员工在给定日期范围内的在职天数,包括入职和离职日期处理。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值