From 34981b009c4f99bb94f0d192ed0a462f173fae04 Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 16 Oct 2023 00:13:24 +0800 Subject: [PATCH 1/2] feat: update sql solution to lc problem: No.1294 --- .../1294.Weather Type in Each Country/README.md | 10 +++++----- .../1294.Weather Type in Each Country/README_EN.md | 10 +++++----- .../1294.Weather Type in Each Country/Solution.sql | 11 +++++------ 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README.md b/solution/1200-1299/1294.Weather Type in Each Country/README.md index 2e97ddf3535b7..fcfd236151e43 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README.md @@ -122,15 +122,15 @@ Morocco 11 月的平均 weather_state 为 (25 + 27 + 31) / 3 = 27.667 所以天 SELECT country_name, CASE - WHEN avg(weather_state) <= 15 THEN 'Cold' - WHEN avg(weather_state) >= 25 THEN 'Hot' + WHEN AVG(weather_state) <= 15 THEN 'Cold' + WHEN AVG(weather_state) >= 25 THEN 'Hot' ELSE 'Warm' END AS weather_type FROM Weather AS w - JOIN Countries AS c ON w.country_id = c.country_id -WHERE date_format(day, '%Y-%m') = '2019-11' -GROUP BY w.country_id; + JOIN Countries USING (country_id) +WHERE Date_Format(day, '%Y-%m') = '2019-11' +GROUP BY 1; ``` diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md index 9772c6a96e9f3..a7e2c121fb7a5 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md @@ -117,15 +117,15 @@ We know nothing about the average weather_state in Spain in November so we do no SELECT country_name, CASE - WHEN avg(weather_state) <= 15 THEN 'Cold' - WHEN avg(weather_state) >= 25 THEN 'Hot' + WHEN AVG(weather_state) <= 15 THEN 'Cold' + WHEN AVG(weather_state) >= 25 THEN 'Hot' ELSE 'Warm' END AS weather_type FROM Weather AS w - JOIN Countries AS c ON w.country_id = c.country_id -WHERE date_format(day, '%Y-%m') = '2019-11' -GROUP BY w.country_id; + JOIN Countries USING (country_id) +WHERE Date_Format(day, '%Y-%m') = '2019-11' +GROUP BY 1; ``` diff --git a/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql b/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql index c1179cf569b54..cef05da5a1141 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql +++ b/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql @@ -1,13 +1,12 @@ -# Write your MySQL query statement below SELECT country_name, CASE - WHEN avg(weather_state) <= 15 THEN 'Cold' - WHEN avg(weather_state) >= 25 THEN 'Hot' + WHEN AVG(weather_state) <= 15 THEN 'Cold' + WHEN AVG(weather_state) >= 25 THEN 'Hot' ELSE 'Warm' END AS weather_type FROM Weather AS w - JOIN Countries AS c ON w.country_id = c.country_id -WHERE date_format(day, '%Y-%m') = '2019-11' -GROUP BY w.country_id; + JOIN Countries USING (country_id) +WHERE Date_Format(day, '%Y-%m') = '2019-11' +GROUP BY 1; From 5516d105c9de0ea54e9bb10b32f2f54af3697f6f Mon Sep 17 00:00:00 2001 From: thinkasany <480968828@qq.com> Date: Mon, 16 Oct 2023 00:15:41 +0800 Subject: [PATCH 2/2] fix: dateformat --- solution/1200-1299/1294.Weather Type in Each Country/README.md | 2 +- .../1200-1299/1294.Weather Type in Each Country/README_EN.md | 2 +- .../1200-1299/1294.Weather Type in Each Country/Solution.sql | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README.md b/solution/1200-1299/1294.Weather Type in Each Country/README.md index fcfd236151e43..d5adb7ffa8866 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README.md @@ -129,7 +129,7 @@ SELECT FROM Weather AS w JOIN Countries USING (country_id) -WHERE Date_Format(day, '%Y-%m') = '2019-11' +WHERE DATE_FORMAT(day, '%Y-%m') = '2019-11' GROUP BY 1; ``` diff --git a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md index a7e2c121fb7a5..33516304071a9 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md +++ b/solution/1200-1299/1294.Weather Type in Each Country/README_EN.md @@ -124,7 +124,7 @@ SELECT FROM Weather AS w JOIN Countries USING (country_id) -WHERE Date_Format(day, '%Y-%m') = '2019-11' +WHERE DATE_FORMAT(day, '%Y-%m') = '2019-11' GROUP BY 1; ``` diff --git a/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql b/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql index cef05da5a1141..a0944ddc293a9 100644 --- a/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql +++ b/solution/1200-1299/1294.Weather Type in Each Country/Solution.sql @@ -8,5 +8,5 @@ SELECT FROM Weather AS w JOIN Countries USING (country_id) -WHERE Date_Format(day, '%Y-%m') = '2019-11' +WHERE DATE_FORMAT(day, '%Y-%m') = '2019-11' GROUP BY 1;