diff --git a/01-BigCountries.sql b/01-BigCountries.sql new file mode 100644 index 0000000..127e2d3 --- /dev/null +++ b/01-BigCountries.sql @@ -0,0 +1,4 @@ +-- Problem 1: Big Countries (https://leetcode.com/problems/big-countries/) +select name, population, area +from world +where area >= 3000000 or population >=25000000 \ No newline at end of file diff --git a/02-NthHighestSalary.sql b/02-NthHighestSalary.sql new file mode 100644 index 0000000..9333094 --- /dev/null +++ b/02-NthHighestSalary.sql @@ -0,0 +1,16 @@ +-- Problem 2: Nth Highest Salary (https://leetcode.com/problems/nth-highest-salary/) + +CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT +BEGIN +RETURN ( + # Write your MySQL query statement below. + with cte as ( + select salary, dense_rank() + over (order by salary desc) as rnk + from employee + ) + select distinct ifnull(salary, null) + from cte + where rnk=N + ); +END \ No newline at end of file diff --git a/03-DeleteDuplicateEmails.sql b/03-DeleteDuplicateEmails.sql new file mode 100644 index 0000000..e2ec28b --- /dev/null +++ b/03-DeleteDuplicateEmails.sql @@ -0,0 +1,5 @@ +-- Problem 3: Delete Duplicate Emails (https://leetcode.com/problems/delete-duplicate-emails/) + +delete p1 from person p1 +cross join person p2 +where p1.email = p2.email and p1.id > p2.id \ No newline at end of file