DATE_ADD(날짜, INTERVAL 더하거나 뺄 값 단위) AS 별칭
DATE_ADD('2024-12-21' INTERVAL 1 DAY) AS DATE
위 함수를 실행하면
2024-12-22 00:00:00
이 나오게된다.
이는 DateFormat함수로 변환해주면 이쁘게 포장된다.
DATE_FORMAT(DATE, '%Y-%m-%d')
2024-12-22
DATE_SUB('2024-12-21', INTERVAL 1 DAY)
2024-12-20
DATEDIFF(날짜, 날짜)
select sum(sum_amount) over w as amount
from cte_sum
window w as (order by visited_on range between interval 6 day preceding and current row)
with cte_sum as(
select visited_on,
sum(amount) as sum_amount
from customer
group by visited_on
),
cte_all as(
select visited_on,
sum(sum_amount) over w as amount,
round(sum(sum_amount) over w / 7, 2) as average_amount
from cte_sum
window w as (order by visited_on range between interval 6 day preceding and current row)
)