- 7일 (즉, 현재 날짜 + 6일 전)에서 고객이 지불한 금액의 평균을 계산하십시오 (평균 금액은 소수점 둘째 자리까지 반올림되어야 함).
WITH cte AS (
SELECT DISTINCT visited_on,
SUM(amount) OVER (ORDER BY visited_on RANGE BETWEEN INTERVAL 6 DAY PRECEDING AND CURRENT ROW) AS amount,
MIN(visited_on) OVER () AS first_date
FROM Customer
)
SELECT visited_on, amount, ROUND(amount/7, 2) AS average_amount
FROM cte
WHERE visited_on >= first_date + 6;