[코드카타] SQL 55 Restaurant Growth

Data_Student·2024년 12월 2일
0

코드카타

목록 보기
64/82

[코드카타] SQL 55 Restaurant Growth
55. Restaurant Growth
https://leetcode.com/problems/restaurant-growth/

You are the restaurant owner and you want to analyze a possible expansion 
(there will be at least one customer every day).
Compute the moving average of how much the customer paid in a seven days 
window (i.e., current day + 6 days before). average_amount should be 
rounded to two decimal places.
Return the result table ordered by visited_on in ascending order.
Select distinct visited_on,
        sum(amount) over(order by visited_on range interval 6 day preceding) amount,
        round(sum(amount) over(order by visited_on range interval 6 day preceding)/7,2) average_amount
from Customer
limit 6, 999
limit를 통한 offset 설정을 통한 문제 해결

0개의 댓글