Skip to content

Commit 029fb78

Browse files
committed
Upload 133
1 parent 6c62c66 commit 029fb78

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ One SQL problem a day for a year
1010
1111
<!-- markdownlint-enable MD028 -->
1212
> [!NOTE]
13-
> `SQL Everyday` has been templatized into `eevveerryyddaayy`. More info [here](https://github.com/ggeerraarrdd/eevveerryyddaayy).
13+
> `SQL Everyday` has been templatized into [`eevveerryyddaayy-template`](https://github.com/ggeerraarrdd/eevveerryyddaayy-template/). For more info, including instructions on installation, configruation and usage, go to [`eevveerryyddaayy`](https://github.com/ggeerraarrdd/eevveerryyddaayy).
1414
1515
_SQL Everyday_ is a personal challenge to solve at least one SQL problem everyday for the next 365 days, starting from September 28, 2024.
1616

@@ -165,6 +165,7 @@ The problems and both submitted and site solutions are documented in individual
165165
| 130 | [Employees Whose Manager Left the Company](https://leetcode.com/problems/employees-whose-manager-left-the-company/description/) | [Solution](solutions/130_employees_whose_manager_left_the_company.md) | LeetCode | Easy | |
166166
| 131 | [Exchange Seats](https://leetcode.com/problems/exchange-seats/description/) | [Solution](solutions/131_exchange_seats.md) | LeetCode | Medium | `CASE` w/ `LAG` w/ `COALESCE` |
167167
| 132 | [Movie Rating](https://leetcode.com/problems/movie-rating/description/) | [Solution](solutions/132_movie_rating.md) | LeetCode | Medium | |
168+
| 133 | [Restaurant Growth](https://leetcode.com/problems/restaurant-growth/description/) | [Solution](solutions/133_restaurant_growth.md) | LeetCode | Medium | |
168169
<!-- Index End - WARNING: Do not delete or modify this markdown comment. -->
169170

170171
## Author(s)

solutions/133_restaurant_growth.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SQL Everyday \#133
2+
3+
## Restaurant Growth
4+
5+
Site: LeetCode\
6+
Difficulty per Site: Medium
7+
8+
## Problem
9+
10+
You are the restaurant owner and you want to analyze a possible expansion (there will be at least one customer every day).
11+
12+
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*.
13+
14+
Return the result table ordered by `visited_on` *in ascending order*. [[Full Description](https://leetcode.com/problems/restaurant-growth/description/)]
15+
16+
## Submitted Solution
17+
18+
```sql
19+
-- Submitted Solution
20+
WITH cte AS (
21+
SELECT
22+
visited_on
23+
,SUM(total_daily) OVER (ORDER BY visited_on ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS amount
24+
,ROUND(AVG(total_daily) OVER (ORDER BY visited_on ROWS BETWEEN 6 PRECEDING AND CURRENT ROW), 2) AS average_amount
25+
FROM
26+
(
27+
SELECT
28+
visited_on
29+
,SUM(amount) as total_daily
30+
FROM Customer
31+
GROUP BY visited_on
32+
ORDER BY visited_on ASC
33+
) AS daily
34+
)
35+
SELECT
36+
*
37+
FROM cte
38+
WHERE visited_on >= DATE((SELECT MIN(visited_on) FROM Customer) + INTERVAL 6 DAY)
39+
;
40+
```
41+
42+
## Site Solution
43+
44+
```sql
45+
-- LeetCode Solution
46+
-- None
47+
```
48+
49+
## Notes
50+
51+
TBD
52+
53+
## NB
54+
55+
TBD
56+
57+
Go to [Index](../?tab=readme-ov-file#index)\
58+
Go to [Overview](../?tab=readme-ov-file)
59+

0 commit comments

Comments
 (0)