From ee1fb7150883f14c071f52c3c0676ebc8f4f6ecc Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Tue, 20 May 2025 17:02:17 -0500 Subject: [PATCH 1/6] Sql1 solution --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index 7b506fe..291e426 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,29 @@ # Sql1 1. Problem 1: Big Countries (https://leetcode.com/problems/big-countries/) +Solution: + +SELECT name, population, area +FROM World +WHERE area >= 3000000 +OR population >=25000000; + 2. Problem 2: Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/) +Solution: + +CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT +BEGIN + RETURN ( + # Write your MySQL query statement below. + with cte as(select id, salary, DENSE_RANK() + OVER (ORDER BY salary DESC) AS dns_rnk + FROM Employee) + + SELECT DISTINCT IFNULL(salary, null) + FROM cte + WHERE dns_rnk = N + + ); +END + 3. Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) From a09dab7f1c7dde9e415fbe94e4c9d8788d74848a Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 16:33:42 -0500 Subject: [PATCH 2/6] Completed Sql1 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 291e426..76809c6 100644 --- a/README.md +++ b/README.md @@ -27,3 +27,8 @@ BEGIN END 3. Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) +Solution: +DELETE P1 +FROM Person P1 +JOIN Person P2 +Where P1.email = P2.email AND P1.id > P2.id From e5c81c59dcf16872c15fff5bb5eecb767e917444 Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 16:38:45 -0500 Subject: [PATCH 3/6] Completed Sql1 --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 76809c6..a9ced1c 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ END 3. Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) Solution: + DELETE P1 FROM Person P1 JOIN Person P2 From 6a6f8c5f36da04ba82e15f4fe7f596a0fbdbd519 Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 16:40:38 -0500 Subject: [PATCH 4/6] Completed Sql1 --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a9ced1c..236e10c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Sql1 1. Problem 1: Big Countries (https://leetcode.com/problems/big-countries/) + Solution: SELECT name, population, area @@ -9,12 +10,12 @@ WHERE area >= 3000000 OR population >=25000000; 2. Problem 2: Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/) + Solution: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN RETURN ( - # Write your MySQL query statement below. with cte as(select id, salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS dns_rnk FROM Employee) @@ -27,6 +28,7 @@ BEGIN END 3. Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) + Solution: DELETE P1 From ac274efa6f66e0a5721c219fda1d483b06b68c4d Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 16:42:06 -0500 Subject: [PATCH 5/6] Completed Sql1 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 236e10c..a9123da 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ WHERE area >= 3000000 OR population >=25000000; 2. Problem 2: Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/) - Solution: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT From 73f5beb6a671dabf9d7e4e6bebb0630432de3f62 Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 21 May 2025 16:43:59 -0500 Subject: [PATCH 6/6] Sql1 Completed --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index a9123da..3cdfd2f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # Sql1 1. Problem 1: Big Countries (https://leetcode.com/problems/big-countries/) - Solution: SELECT name, population, area @@ -27,7 +26,6 @@ BEGIN END 3. Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) - Solution: DELETE P1