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
10 changes: 10 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
WITH CTE AS(
SELECT fail_date as 'dat' , 'failed' As period_state , rank() OVER(ORDER by fail_date) as 'rnk' from failed
WHERE YEAR(fail_date) = 2019
UNION ALL
SELECT success_date as 'dat' , 'succeeded' As period_state, rank() OVER(ORDER by success_date) as 'rnk' from Succeeded
WHERE YEAR(success_date) = 2019
)
SELECT period_state , MIN(dat) as start_date , MAX(dat) as end_date FROM (SELECT * , rank() OVER(order by dat) - rnk as diff from CTE)as y
group by diff, period_state
order by start_date;
12 changes: 12 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
WITH first as(
SELECT name as 'America', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk' From student WHERE continent = 'America'
),
second as(
SELECT name as 'Asia', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk' From student WHERE continent = 'Asia'
),
third as(
SELECT name as 'Europe', ROW_NUMBER() OVER(ORDER BY name) AS 'rnk' From student WHERE continent = 'Europe'
)

SELECT America , Asia , Europe FROM second RIGHT JOIN first on first.rnk = second.rnk LEFT JOIN third
ON first.rnk = third.rnk;
19 changes: 19 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
WITH companyAvg as(
Select date_format(pay_date,'%Y-%m') as 'pay_month',
AVG(amount) as 'companyavg' from salary group by pay_month
),
deptAvg as(
Select date_format(pay_date,'%Y-%m') as 'pay_month',
department_id, AVG(amount) as 'deptavg' from salary join employee
ON salary.employee_id = employee.employee_id
group by department_id, pay_month
)
SELECT deptAvg.pay_month, department_id,
(
CASE
WHEN deptavg>companyavg THEN 'higher'
WHEN deptavg<companyavg THEN 'lower'
ELSE 'same'
END
) as 'comparison' from companyAvg JOIN deptAvg ON
deptAvg.pay_month = companyAvg.pay_month
2 changes: 2 additions & 0 deletions Problem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
WITH CTE AS(SELECT player_id, event_date as 'first_login', RANK() OVER (PARTITION BY player_id order by event_date) as 'rnk' from activity)
Select player_id, first_login from CTE where rnk = 1