diff --git a/problem1.sql b/problem1.sql new file mode 100644 index 0000000..7674c98 --- /dev/null +++ b/problem1.sql @@ -0,0 +1,5 @@ +-- Write your PostgreSQL query statement below +SELECT name, population, area +FROM World +WHERE area >= 3000000 +OR population >= 25000000; \ No newline at end of file diff --git a/problem2.sql b/problem2.sql new file mode 100644 index 0000000..1317646 --- /dev/null +++ b/problem2.sql @@ -0,0 +1,14 @@ +CREATE OR REPLACE FUNCTION NthHighestSalary(N INT) RETURNS TABLE (Salary INT) AS $$ +BEGIN + RETURN QUERY ( + -- Write your PostgreSQL query statement below. + WITH CTE AS ( + SELECT e.salary, DENSE_RANK() OVER(ORDER BY e.salary DESC) AS rnk + FROM Employee e + ) + SELECT DISTINCT c.salary + FROM CTE c + WHERE c.rnk = N + ); +END; +$$ LANGUAGE plpgsql; \ No newline at end of file diff --git a/problem3.sql b/problem3.sql new file mode 100644 index 0000000..86a6898 --- /dev/null +++ b/problem3.sql @@ -0,0 +1,5 @@ +-- Write your PostgreSQL query statement below +DELETE FROM Person +USING Person p2 +WHERE Person.email = p2.email +AND Person.id > p2.id;