From 8de503594bd2c01eb28d74f6c3a167fcbd2b4637 Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 19:10:49 -0500 Subject: [PATCH 1/3] Completed Rank Scores --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index c2318de..96799ed 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,11 @@ # Sql2 Problem 1 : Rank Scores (https://leetcode.com/problems/rank-scores/ ) +Solution: + +Select score, DENSE_RANK() +OVER (ORDER BY score DESC) AS 'rank' +from Scores Problem 2 : Exchange Seats (https://leetcode.com/problems/exchange-seats/ ) From 35e225bf9f554852dd819b5bd599367c945e327d Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Thu, 22 May 2025 19:02:14 -0500 Subject: [PATCH 2/3] Completed Exchange Seats --- README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/README.md b/README.md index 96799ed..194cbfc 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,16 @@ OVER (ORDER BY score DESC) AS 'rank' from Scores Problem 2 : Exchange Seats (https://leetcode.com/problems/exchange-seats/ ) +Solution: + +SELECT ( + CASE + WHEN MOD(id,2) != 0 AND id = cnts THEN id + WHEN MOD(id,2) != 0 AND id != cnts THEN id+1 + ELSE id-1 + END +)AS 'id', student FROM seat, (SELECT COUNT(*) AS 'cnts' FROM Seat) AS seat_counts +ORDER BY id Problem 3 : Tree Node (https://leetcode.com/problems/tree-node/ ) From 4531fa6404c7d5b09e68af5f59feacc6ad5f8d90 Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Tue, 27 May 2025 19:44:59 -0500 Subject: [PATCH 3/3] Completed Tree Node & Deparment Top 3 Salaries --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 194cbfc..ea4d712 100644 --- a/README.md +++ b/README.md @@ -20,5 +20,28 @@ SELECT ( ORDER BY id Problem 3 : Tree Node (https://leetcode.com/problems/tree-node/ ) +Solution: + +Select id, ( + CASE + when p_id IS Null + then "Root" + when id In (Select Distinct p_id from tree ) then "Inner" + else "Leaf" + end) AS type +from Tree +order by id ASC Problem 4 : Deparment Top 3 Salaries (https://leetcode.com/problems/department-top-three-salaries/ ) +Solution: + +SELECT d.name AS Department, e.name AS Employee, e.salary AS Salary +FROM Employee e +JOIN Department d ON e.departmentId = d.id +WHERE 3 > ( + SELECT COUNT(DISTINCT e2.salary) + FROM Employee e2 + WHERE e2.departmentId = e.departmentId + AND e2.salary > e.salary +) +ORDER BY d.name, e.salary DESC; \ No newline at end of file