1321. Restaurant Growth

https://leetcode.com/problems/restaurant-growth

Description

Table: Customer


+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| customer\_id   | int     |
| name          | varchar |
| visited\_on    | date    |
| amount        | int     |
+---------------+---------+
(customer\_id, visited\_on) is the primary key for this table.
This table contains data about customer transactions in a restaurant.
visited\_on is the date on which the customer with ID (customer\_id) have visited the restaurant.
amount is the total paid by a customer.

You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).

Write an SQL query to compute moving average of how much customer paid in a 7 days window (current day + 6 days before) .

The query result format is in the following example:

Return result table ordered by visited_on.

average_amountshould be rounded to 2 decimal places, all dates are in the format ('YYYY-MM-DD').

ac

Last updated

Was this helpful?