Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
Tags
- Windows
- tomcat
- Mac
- Source
- profile
- Windows 10
- find
- plugin
- port
- 단축키
- 줄바꿈 문자
- Quartz
- IntelliJ
- web.xml
- netsh
- vscode
- VirtualBox
- 네트워크
- bash
- JavaScript
- resource
- xargs
- import
- grep
- lsof
- maVen
- Eclipse
- ssh
- GIT
- context
Archives
- Today
- Total
develog
[mysql] 달력 출력 본문
이번 달 달력 출력
with recursive
T as (
select last_day(curdate() - interval 1 month) + interval 1 day as startDate
union all
select startDate + interval 1 day from T where last_day(curdate()) > startDate
)
select *
from T
;
특정 달 달력 출력
with recursive
T as (
select last_day(str_to_date('20240201', '%Y%m%d') - interval 1 month) + interval 1 day as startDate
union all
select startDate + interval 1 day from T where last_day(str_to_date('20240201', '%Y%m%d')) > startDate
)
select *
from T
;
시작일, 종료일 사이에 날짜 구하기
set @start_dt = '20240311';
set @end_dt = '20240320';
WITH RECURSIVE
cal_dates AS (
SELECT
DATE_FORMAT(@start_dt, '%Y-%m-%d') AS cal_dt
UNION
SELECT
DATE_FORMAT(DATE_ADD(cal_dt, INTERVAL 1 DAY), '%Y-%m-%d')
FROM cal_dates
WHERE date_format(DATE_ADD(cal_dt, INTERVAL 1 DAY), '%Y%m%d') <= @end_dt
)
SELECT *
FROM cal_dates
;