yoursyun
임의의 기간 날짜 테이블 만들기 본문
22.03.07 ~ 03.13 기간 YYYYMMDD 임시 테이블 만들기 ( Maria 10.2.1 버전이상 )
WITH RECURSIVE CTE AS (
SELECT DATE_FORMAT('20220307', '%Y-%m-%d') AS DT FROM DUAL
UNION ALL
SELECT DATE_ADD(DT, INTERVAL 1 DAY) FROM CTE
WHERE DT < DATE_FORMAT('20220313', '%Y-%m-%d')
)
SELECT date_format(DT,'%Y%m%d') AS TDATE FROM CTE;
실행결과
10.2.1 이하
SELECT
DATE_FORMAT(DATE_ADD('20220301', INTERVAL seq - 1 DAY), '%Y%m%d') AS TDATE
FROM (SELECT @num := @num + 1 AS seq
FROM information_schema.tables a
, information_schema.tables b
, (SELECT @num := 0) c
) T
WHERE seq <= DATEDIFF('20220308', '20220301') + 1
반응형