--每天上下班时间+每天休假情况
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
NC每日休假信息SQL
猜你喜欢
转载自blog.csdn.net/hwq293/article/details/80131283
今日推荐
周排行