티베로(Tibero) 오라클(Oracle)
오라클 휴일 제외 평일근무 일수 sql
xemaker
2019. 3. 15. 09:00
주말 및 휴일을 제외하고 평일만 가져오는 오라클 쿼리를 만들어 보겠다.
select count(1) from
(
select to_char(sdt+level-1'yyyymmdd') dt, to_char(sdt+level-1'D') D from
(
select trunc(to_date('20190301'),'MM') sdt, last_day(to_date('20190331')) edt from dual
)
connect by level <= edt-sdt+1
) a
,
(
select holi_year||holi_day dt
from holiday
where to_char(to_date(holi_year||holi_day),'yyyymm')=substr('20190301',0,6)
) b
where a.dt=b.dt(+)
and a.d not in ('1','7')
and b.dt is null
끝~
휴일테이블에서 그 달의 휴일 정보를 가져오고 토일,빼고 해당달의 평일 일 수 를 가져온다.
connect by level 에 의해 1일 부터 말일 까지 쫙~ 나온다. 그걸 count를 하니 평일 일수가 나온다.
connect by level 에 대한 상세 정보는 다음 글에~
select count(1) from
(
select to_char(sdt+level-1'yyyymmdd') dt, to_char(sdt+level-1'D') D from
(
select trunc(to_date('20190301'),'MM') sdt, last_day(to_date('20190331')) edt from dual
)
connect by level <= edt-sdt+1
) a
,
(
select holi_year||holi_day dt
from holiday
where to_char(to_date(holi_year||holi_day),'yyyymm')=substr('20190301',0,6)
) b
where a.dt=b.dt(+)
and a.d not in ('1','7')
and b.dt is null
끝~
휴일테이블에서 그 달의 휴일 정보를 가져오고 토일,빼고 해당달의 평일 일 수 를 가져온다.
connect by level 에 의해 1일 부터 말일 까지 쫙~ 나온다. 그걸 count를 하니 평일 일수가 나온다.
connect by level 에 대한 상세 정보는 다음 글에~