From 5b027729bd4da01b5e22b7a4733d0f5c5b84477f Mon Sep 17 00:00:00 2001 From: Kaustubhk28 <99148707+Kaustubhk28@users.noreply.github.com> Date: Fri, 20 Dec 2024 19:48:41 -0500 Subject: [PATCH] Done SQL1 --- SQL1.sql | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 SQL1.sql diff --git a/SQL1.sql b/SQL1.sql new file mode 100644 index 0000000..cf3b5a0 --- /dev/null +++ b/SQL1.sql @@ -0,0 +1,29 @@ +# Problem 1: Big Countries (https://leetcode.com/problems/big-countries/) +# Write your MySQL query statement below +SELECT name, population, area +FROM World +WHERE area >= 3000000 OR population >= 25000000; + +# Problem 2: Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/) +# Write your MySQL query statement below +CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT +BEGIN + RETURN ( + # Write your MySQL query statement below. + WITH TEMP AS + ( + SELECT id, salary, DENSE_RANK() OVER(ORDER BY salary DESC) AS ranks + FROM Employee + ) + SELECT IFNULL(salary, null) + FROM TEMP + WHERE ranks = N + ); +END + +# Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) +# Write your MySQL query statement below +DELETE p2 +FROM Person p1 +JOIN Person p2 +ON p1.email = p2.email AND p2.id > p1.id \ No newline at end of file