Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Write your MySQL query statement below
SELECT s1.score, (
SELECT COUNT(DISTINCT s2.score)
FROM Scores s2
WHERE s2.score >= s1.score
) AS 'rank' FROM Scores s1
ORDER BY s1.score DESC;
9 changes: 9 additions & 0 deletions problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below
SELECT
CASE WHEN id % 2 = 0 THEN id - 1
WHEN id % 2 = 1 AND id + 1 <= (SELECT MAX(id) FROM Seat) THEN id + 1
ELSE id
END AS id,
student
FROM Seat
ORDER BY id;
8 changes: 8 additions & 0 deletions problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Write your MySQL query statement below
SELECT id,
CASE
WHEN p_id IS null THEN 'Root'
WHEN id IN (SELECT p_id FROM Tree WHERE p_id IS NOT NULL) THEN 'Inner'
ELSE 'Leaf'
END AS 'type'
FROM Tree;
13 changes: 13 additions & 0 deletions problem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Write your MySQL query statement below
WITH RankedSalaries AS (
SELECT
d.name AS Department,
e.name AS Employee,
e.salary AS Salary,
DENSE_RANK() OVER(PARTITION BY e.departmentId ORDER BY e.salary DESC) AS salary_rank
FROM Department d
JOIN Employee e
ON d.id = e.departmentId)
SELECT Department, Employee, Salary
FROM RankedSalaries
WHERE salary_rank <= 3;