날짜 비교를 하려고하니 이런게 나온다..
select a.Date
from (
select LAST_DAY('2018-11-01' - interval 1 month) - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as Date
from (select 0 as a union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all
select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all
select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all
select 3 union all select 4 union all select 5 union all
select 6 union all select 7 union all select 8 union all
select 9) as c
) a
order by 1 desc
--
이번달만
원하는 달에 now()를 쓰면 이번달에 포함된 날짜만 출력될것이다.
SELECT DATETEMP.m as date
from (
select LAST_DAY("원하는 달의 날짜") - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as m
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) DATETEMP
WHERE DATETEMP.m > LAST_DAY("원하는 달의 날짜" - interval 1 month)
--
SELECT DATETEMP.m as date
from (
select LAST_DAY('2018-11-27') - INTERVAL (a.a + (10 * b.a) + (100 * c.a)) DAY as m
from (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as a
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as b
cross join (select 0 as a union all select 1 union all select 2 union all select 3 union all select 4 union all select 5 union all select 6 union all select 7 union all select 8 union all select 9) as c
) DATETEMP
WHERE DATETEMP.m > LAST_DAY('2018-11-27' - interval 1 month)
결과
--
date
2018-11-30
2018-11-29
2018-11-28
2018-11-27
2018-11-26
2018-11-25
2018-11-24
2018-11-23
2018-11-22
2018-11-21
2018-11-20
2018-11-19
2018-11-18
2018-11-17
2018-11-16
2018-11-15
2018-11-14
2018-11-13
2018-11-12
2018-11-11
2018-11-10
2018-11-09
2018-11-08
2018-11-07
2018-11-06
2018-11-05
2018-11-04
2018-11-03
2018-11-02
2018-11-01
'데이터베이스 > MSSQL' 카테고리의 다른 글
geography 자료형 (0) | 2019.02.28 |
---|---|
저번달 1일 마지막일 이번달 1일 마지막일 (0) | 2018.12.20 |
BETWEEN (0) | 2018.11.20 |
expression을(를) 데이터 형식 int(으)로 변환하는 중 산술 오버플로 오류가 발생했습니다. (0) | 2018.11.19 |
ORDER BY string as number (0) | 2018.11.06 |