Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Q1_Solution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select
name
, population
, area
from
World
where (area >= 3000000) or (population >= 25000000)
14 changes: 14 additions & 0 deletions Q1_Solution_UsingDECLARE_SET
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE FUNCTION GetNthHighestSalary(N INT) RETURNS INT
BEGIN
DECLARE M INT
SET M = N-1
RETURN
(
select
distinct salary
from
Employee
order by desc
limit M, 1
);
END
12 changes: 12 additions & 0 deletions Q3_Sql1_solution.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
with ranked_emails as
(
select
id
, email
, row_number() over(partition by email order by id) as rnk
from
Person
)
delete
from person p
where p.id in (select ranked_emails.id from ranked_emails where rnk > 1)
12 changes: 12 additions & 0 deletions SQL1_Q2_Question.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
RETURN (
with cte as (
select
*
, dense_rank() over(order by salary desc) as rnk
from Employee
)
select distinct ifnull(salary, null) from cte where rnk = N
);
END
4 changes: 4 additions & 0 deletions sql1_q3_crossjoin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DELETE p1
from person p1
cross join person p2 where p1.email = p2.email
and p1.id > p2.id