/* selectHoliday */
SELECT a.YYYYMM AS YY /*년월*/
, a.YYYYMM || b.DT AS YMD /*년월일*/
, b.DT /*일자*/
, to_char(to_date(a.YYYYMM || b.DT, 'yyyymmdd'), 'd') AS DOTW_CLSF_CD /*요일(1-일, 2-월, 3-화, 4-수, 5-목, 6-금, 7-토)*/
, CASE WHEN c.DT IS NOT NULL THEN 'Y'
WHEN to_char(to_date(a.YYYYMM || b.DT, 'yyyymmdd'), 'd') IN ('1', '7') THEN 'Y'
ELSE 'N' END AS HLDY_YN /*휴일여부*/
, c.BS_DT_NM
, to_char(COALESCE(c.CHNG_DTTM, c.REG_DTTM), 'YYYY-MM-DD HH24:MI') AS CHNG_DTTM /*수정일시*/
,COALESCE(c.CHNG_USER_ID, c.RGNT_ID) AS CHNG_USER_ID /*수정자*/
FROM (
SELECT to_date(to_char(date( #{yearMm} '01') + interval'31 days', 'yyyymm') || '01', 'yyyymmdd') + interval '-1 days' AS MAX_DD
, #{yearMm} AS YYYYMM
) a
INNER JOIN
(
select '01' as DT union all
select '02' as DT union all
select '03' as DT union all
select '04' as DT union all
select '05' as DT union all
select '06' as DT union all
select '07' as DT union all
select '08' as DT union all
select '09' as DT union all
select '10' as DT union all
select '11' as DT union all
select '12' as DT union all
select '13' as DT union all
select '14' as DT union all
select '15' as DT union all
select '16' as DT union all
select '17' as DT union all
select '18' as DT union all
select '19' as DT union all
select '20' as DT union all
select '21' as DT union all
select '22' as DT union all
select '23' as DT union all
select '24' as DT union all
select '25' as DT union all
select '26' as DT union all
select '27' as DT union all
select '28' as DT union all
select '29' as DT union all
select '30' as DT union all
select '31' as DT union all
) b
on 1=1
left outer join DTJM1023 c
on c.DT = a.YYYYMM || b.DT
and c.HLDY_YN ='Y'
where 1=1
and to_char(a.MAX_DD, 'dd) >= b.DT
order by 2
a --> 현재년월(YYYYMM), 현재년월의 마지막날짜(30일? 31일? 2월이면 28,29? check)
to_date(A, B)
b -->
c --> 휴일관리테이블(DTJM1023)
날짜와 휴일유무 를 대조
'IT > PostgresSQL' 카테고리의 다른 글
SQLD 공부법 정리 (0) | 2023.08.16 |
---|---|
데이터 모델링의 이해 (0) | 2023.08.10 |
[SQL] 리스트 잘라서 보여주는 쿼리 (0) | 2023.08.09 |
[Oracle SQL] WITH절 사용법 및 예제 정리 (0) | 2023.07.03 |
[Oralce SQL] 정규식 regexp_replace() 함수 (0) | 2023.07.03 |