forked from doocs/leetcode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update solutions to lc problems: No.0570,0620,1251,1280,1934 (d…
…oocs#1834) * No.0570.Managers with at Least 5 Direct Reports * No.0620.Not Boring Movies * No.1251.Average Selling Price * No.1280.Students and Examinations * No.1934.Confirmation Rate
- Loading branch information
Showing
15 changed files
with
105 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 9 additions & 11 deletions
20
solution/0500-0599/0570.Managers with at Least 5 Direct Reports/Solution.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,11 @@ | ||
# Write your MySQL query statement below | ||
WITH | ||
T AS ( | ||
SELECT | ||
managerId, | ||
COUNT(1) OVER (PARTITION BY managerId) AS cnt | ||
FROM Employee | ||
) | ||
SELECT DISTINCT name | ||
SELECT name | ||
FROM | ||
Employee AS e | ||
JOIN T AS t ON e.id = t.managerId | ||
WHERE cnt >= 5; | ||
Employee | ||
JOIN ( | ||
SELECT managerId AS id, COUNT(1) AS cnt | ||
FROM Employee | ||
GROUP BY 1 | ||
HAVING cnt >= 5 | ||
) AS t | ||
USING (id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# Write your MySQL query statement below | ||
SELECT * | ||
FROM Cinema | ||
WHERE description != 'boring' AND id % 2 = 1 | ||
ORDER BY rating DESC; | ||
WHERE description != 'boring' AND id & 1 = 1 | ||
ORDER BY 4 DESC; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
# Write your MySQL query statement below | ||
SELECT | ||
p.product_id, | ||
IFNULL(ROUND(SUM(units * price) / SUM(units), 2), 0) AS average_price | ||
IFNULL(ROUND(SUM(price * units) / SUM(units), 2), 0) AS average_price | ||
FROM | ||
Prices AS p | ||
LEFT JOIN UnitsSold AS u | ||
ON p.product_id = u.product_id AND purchase_date BETWEEN start_date AND end_date | ||
GROUP BY product_id; | ||
GROUP BY 1; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 6 additions & 10 deletions
16
solution/1200-1299/1280.Students and Examinations/Solution.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
# Write your MySQL query statement below | ||
SELECT | ||
a.student_id, | ||
student_name, | ||
b.subject_name, | ||
COUNT(c.subject_name) AS attended_exams | ||
SELECT student_id, student_name, subject_name, COUNT(e.student_id) AS attended_exams | ||
FROM | ||
Students AS a | ||
CROSS JOIN Subjects AS b | ||
LEFT JOIN Examinations AS c ON a.student_id = c.student_id AND b.subject_name = c.subject_name | ||
GROUP BY a.student_id, b.subject_name | ||
ORDER BY a.student_id, b.subject_name; | ||
Students | ||
JOIN Subjects | ||
LEFT JOIN Examinations AS e USING (student_id, subject_name) | ||
GROUP BY 1, 3 | ||
ORDER BY 1, 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.