From 3b3f6cb39c1398a657ab9319f50b370f5295d41d Mon Sep 17 00:00:00 2001 From: Sangeeth Santhosh <73825180+sangeeths29@users.noreply.github.com> Date: Tue, 20 May 2025 00:30:09 -0700 Subject: [PATCH] Add files via upload --- problem1.sql | 5 +++++ problem2.sql | 14 ++++++++++++++ problem3.sql | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 problem1.sql create mode 100644 problem2.sql create mode 100644 problem3.sql 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;