NC每日休假信息SQL

--每天上下班时间+每天休假情况
select v.* ,
(select  
(case when v.if_rest='Y' then 0 
else 
    (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.endtime then 1 
          when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<=v.endtime then b.leavehour 
     else 
          (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime then
                (case when v.pk_shift<>'10018G10000000019QJW' then  (to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.begintime)*24/v.gzsj --to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=reendtime then
                      else (case when to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.reendtime then (3+(to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.reendtime)*24) /v.gzsj
                                 else 3 /v.gzsj
                                 end
                           )
                      end
                )
           else ( case when  to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime and to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.endtime then
                              (case when v.pk_shift<>'10018G10000000019QJW' then  (v.endtime-to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss'))*24/v.gzsj
                                    else (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.restarttime then (5+(v.restarttime-to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss'))*24)/v.gzsj 
                                         else 5/v.gzsj
                                         end
                                         )

                                      end)
                      else 0 end
                )
           end
          )
     end
    )
end)
 from tbm_leaveb b
         inner join tbm_leaveh h
            on b.pk_leaveh = h.pk_leaveh
         where h.pk_leavetype = '1002Z710000000021ZLJ'
           and h.pk_psndoc=v.pk_psndoc
           and v.calendar between b.leavebegindate and b.leaveenddate) al,           
(select  
(case when v.if_rest='Y' then 0 
else 
    (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.endtime then 1 
          when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<=v.endtime then b.leavehour 
     else 
          (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime then
                (case when v.pk_shift<>'10018G10000000019QJW' then  (to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.begintime)*24/v.gzsj --to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=reendtime then
                      else (case when to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.reendtime then (3+(to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.reendtime)*24) /v.gzsj
                                 else 3 /v.gzsj
                                 end
                           )
                      end
                )
           else ( case when  to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime and to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.endtime then
                              (case when v.pk_shift<>'10018G10000000019QJW' then  (v.endtime-to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss'))*24/v.gzsj
                                    else (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.restarttime then (5+(v.restarttime-to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss'))*24)/v.gzsj 
                                         else 5/v.gzsj
                                         end
                                         )

                                      end)
                      else 0 end
                )
           end
          )
     end
    )
end)
 from tbm_leaveb b
         inner join tbm_leaveh h
            on b.pk_leaveh = h.pk_leaveh
         where h.pk_leavetype = '1002Z710000000021ZLB'
           and h.pk_psndoc=v.pk_psndoc
           and v.calendar between b.leavebegindate and b.leaveenddate) shijia,
(select  
(case when v.if_rest='Y' then 0 
else 
    (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.endtime then 1 
          when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<=v.endtime then b.leavehour 
     else 
          (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.begintime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime then
                (case when v.pk_shift<>'10018G10000000019QJW' then  (to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.begintime)*24/v.gzsj --to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=reendtime then
                      else (case when to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>=v.reendtime then (3+(to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')-v.reendtime)*24) /v.gzsj
                                 else 3 /v.gzsj
                                 end
                           )
                      end
                )
           else ( case when  to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')>v.begintime and to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<v.endtime and to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss')>v.endtime then
                              (case when v.pk_shift<>'10018G10000000019QJW' then  (v.endtime-to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss'))*24/v.gzsj
                                    else (case when to_date(b.leavebegintime ,'yyyy-mm-dd hh24:mi:ss')<=v.restarttime then (5+(v.restarttime-to_date(b.leaveendtime ,'yyyy-mm-dd hh24:mi:ss'))*24)/v.gzsj 
                                         else 5/v.gzsj
                                         end
                                         )

                                      end)
                      else 0 end
                )
           end
          )
     end
    )
end)
 from tbm_leaveb b
         inner join tbm_leaveh h
            on b.pk_leaveh = h.pk_leaveh
         where h.pk_leavetype = '1002Z710000000021ZLD'
           and h.pk_psndoc=v.pk_psndoc
           and v.calendar between b.leavebegindate and b.leaveenddate) bingjia                 


from 
(SELECT t.pk_psndoc,t.pk_org,t.calendar,t.if_rest,s.pk_shift,s.gzsj,
       to_date(t.calendar||' '||s.begintime,'yyyy-mm-dd hh24:mi:ss') as begintime,
       (case when s.endday=1 then to_date(t.calendar||' '||s.endtime,'yyyy-mm-dd hh24:mi:ss')+1 else to_date(t.calendar||' '||s.endtime,'yyyy-mm-dd hh24:mi:ss') end)  as endtime,
       (to_date(t.calendar||' '||(select wt.JSSJ from bd_wt wt where wt.pk_shift=s.pk_shift and wt.timeid=0) ,'yyyy-mm-dd hh24:mi:ss')) as restarttime,
       (to_date(t.calendar||' '||(select wt.KSSJ from bd_wt wt where wt.pk_shift=s.pk_shift and wt.timeid=1),'yyyy-mm-dd hh24:mi:ss'))as reendtime

  FROM tbm_psncalendar t
  inner join bd_shift s
  on t.pk_shift=s.pk_shift
 WHERE t.pk_org='00016H10000000000BIV') v 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值