Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit dad331d

Browse files
committed
Adding new Solutions
1 parent 82a12d3 commit dad331d

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

‎README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Leetcode SQL Questions & Solutions <br/>
22
#### Repository Contains :<br/>
33

4-
(1) All Leetcode SQL Question Solutions (212 Questions)<br/>
4+
(1) All Leetcode SQL Question Solutions <br/>
55
(2) PostgreSQL Dump File (leetcodedb.sql)<br/>
66

77
#### Problem statements of all questions including leetcode premium questions :<br/>

‎dump_file/leetcodedb.sql

-13 Bytes
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
WITH RECURSIVE exploded_sales AS (
2+
SELECT product_id,period_start,period_end,average_daily_sales
3+
FROM sales_1384
4+
UNION
5+
SELECT product_id,period_start+1 AS period_start,period_end,average_daily_sales
6+
FROM exploded_sales
7+
WHERE period_start < period_end
8+
)
9+
SELECT es.product_id,p.product_name,EXTRACT(YEAR FROM period_start) AS report_year,SUM(average_daily_sales)
10+
FROM exploded_sales es
11+
INNER JOIN product_1384 p ON es.product_id=p.product_id
12+
GROUP BY es.product_id,p.product_name,EXTRACT(YEAR FROM period_start)
13+
ORDER BY es.product_id,report_year;

‎medium/1321. Restaurant Growth.sql

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,23 @@ cte2 AS(
1616
SELECT visited_on,sum_amount,average_amount
1717
FROM cte2
1818
WHERE num>=7;
19+
20+
---------------------------------------------------------------------------------------------------------------------------------
21+
22+
WITH daily_spent AS (
23+
SELECT visited_on,SUM(amount) AS amount,
24+
ROW_NUMBER() OVER (ORDER BY visited_on) AS rn
25+
FROM customer_1321
26+
GROUP BY visited_on
27+
),
28+
moving_averages AS (
29+
SELECT visited_on,rn,
30+
ROUND((AVG(amount) OVER (ORDER BY visited_on ROWS BETWEEN 6 PRECEDING AND CURRENT ROW)),2) AS running_avg
31+
FROM daily_spent
32+
ORDER BY visited_on
33+
)
34+
SELECT *
35+
FROM moving_averages
36+
WHERE rn >= 7;
37+
38+
-- Window functions are evaluated after group by clause got executed, and window functions are applied to the result of group by clause.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /