From 15254aedf2ecbe6de793b9fe9514727f7bcd84d1 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 8 Jan 2024 15:39:56 +0800 Subject: [PATCH 1/3] feat: add sql solution to lc problem: No.1321 --- .../1300-1399/1321.Restaurant Growth/README.md | 16 ++++++++++++++++ .../1321.Restaurant Growth/README_EN.md | 16 ++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/solution/1300-1399/1321.Restaurant Growth/README.md b/solution/1300-1399/1321.Restaurant Growth/README.md index 1fe8b4e3532d4..2dc9bdc7135ec 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README.md +++ b/solution/1300-1399/1321.Restaurant Growth/README.md @@ -104,4 +104,20 @@ FROM t WHERE rk > 6; ``` +### **SQL** + +```sql +# Write your MySQL query statement below +SELECT + a.visited_on, + SUM(b.amount) AS amount, + ROUND(SUM(b.amount) / 7, 2) AS average_amount +FROM + (SELECT DISTINCT visited_on FROM customer) AS a + JOIN customer AS b ON DATEDIFF(a.visited_on, b.visited_on) BETWEEN 0 AND 6 +WHERE a.visited_on >= (SELECT MIN(visited_on) FROM customer) + 6 +GROUP BY a.visited_on +ORDER BY a.visited_on; +``` + diff --git a/solution/1300-1399/1321.Restaurant Growth/README_EN.md b/solution/1300-1399/1321.Restaurant Growth/README_EN.md index 5f60697e754ce..870cf6127109c 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README_EN.md +++ b/solution/1300-1399/1321.Restaurant Growth/README_EN.md @@ -100,4 +100,20 @@ FROM t WHERE rk > 6; ``` +### **SQL** + +```sql +# Write your MySQL query statement below +SELECT + a.visited_on, + SUM(b.amount) AS amount, + ROUND(SUM(b.amount) / 7, 2) AS average_amount +FROM + (SELECT DISTINCT visited_on FROM customer) AS a + JOIN customer AS b ON DATEDIFF(a.visited_on, b.visited_on) BETWEEN 0 AND 6 +WHERE a.visited_on >= (SELECT MIN(visited_on) FROM customer) + 6 +GROUP BY a.visited_on +ORDER BY a.visited_on; +``` + From e87dc2b185330a03f46d1c7cfa424f58fa68eab2 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 8 Jan 2024 15:48:40 +0800 Subject: [PATCH 2/3] fix: remove title --- solution/1300-1399/1321.Restaurant Growth/README.md | 2 -- solution/1300-1399/1321.Restaurant Growth/README_EN.md | 2 -- 2 files changed, 4 deletions(-) diff --git a/solution/1300-1399/1321.Restaurant Growth/README.md b/solution/1300-1399/1321.Restaurant Growth/README.md index 2dc9bdc7135ec..594bbd6c30902 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README.md +++ b/solution/1300-1399/1321.Restaurant Growth/README.md @@ -104,8 +104,6 @@ FROM t WHERE rk > 6; ``` -### **SQL** - ```sql # Write your MySQL query statement below SELECT diff --git a/solution/1300-1399/1321.Restaurant Growth/README_EN.md b/solution/1300-1399/1321.Restaurant Growth/README_EN.md index 870cf6127109c..e43d0842af568 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README_EN.md +++ b/solution/1300-1399/1321.Restaurant Growth/README_EN.md @@ -100,8 +100,6 @@ FROM t WHERE rk > 6; ``` -### **SQL** - ```sql # Write your MySQL query statement below SELECT From 097258a3ccaff6e78db83a7078fe03d9ff52f7c4 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 8 Jan 2024 15:54:30 +0800 Subject: [PATCH 3/3] fix: opt --- solution/1300-1399/1321.Restaurant Growth/README.md | 4 ++-- solution/1300-1399/1321.Restaurant Growth/README_EN.md | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/solution/1300-1399/1321.Restaurant Growth/README.md b/solution/1300-1399/1321.Restaurant Growth/README.md index 594bbd6c30902..174d70118f3b1 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README.md +++ b/solution/1300-1399/1321.Restaurant Growth/README.md @@ -114,8 +114,8 @@ FROM (SELECT DISTINCT visited_on FROM customer) AS a JOIN customer AS b ON DATEDIFF(a.visited_on, b.visited_on) BETWEEN 0 AND 6 WHERE a.visited_on >= (SELECT MIN(visited_on) FROM customer) + 6 -GROUP BY a.visited_on -ORDER BY a.visited_on; +GROUP BY 1 +ORDER BY 1; ``` diff --git a/solution/1300-1399/1321.Restaurant Growth/README_EN.md b/solution/1300-1399/1321.Restaurant Growth/README_EN.md index e43d0842af568..ab91dc98bd5f9 100644 --- a/solution/1300-1399/1321.Restaurant Growth/README_EN.md +++ b/solution/1300-1399/1321.Restaurant Growth/README_EN.md @@ -110,8 +110,8 @@ FROM (SELECT DISTINCT visited_on FROM customer) AS a JOIN customer AS b ON DATEDIFF(a.visited_on, b.visited_on) BETWEEN 0 AND 6 WHERE a.visited_on >= (SELECT MIN(visited_on) FROM customer) + 6 -GROUP BY a.visited_on -ORDER BY a.visited_on; +GROUP BY 1 +ORDER BY 1; ```