■ GENERATE_SERIES 함수 : 해당 월 날짜의 주차 구하기

------------------------------------------------------------------------------------------------------------------------

 

SELECT

    TARGET_DATE               AS "날짜"

   ,TO_CHAR(TARGET_DATE, 'W') AS "주차"

FROM

(

    SELECT DATE_TRUNC('MONTH', CURRENT_DATE)::DATE + I AS TARGET_DATE

    FROM GENERATE_SERIES(0, 30) AS T(I)

) A

WHERE EXTRACT(MONTH FROM TARGET_DATE) = EXTRACT(MONTH FROM CURRENT_DATE);

 

------------------------------------------------------------------------------------------------------------------------

Posted by 사용자 icodebroker
TAG