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
17 changes: 17 additions & 0 deletions Problem1_ContiguousDate.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Write your MySQL query statement below
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
select success_date as 'dat','succeeded' as period_state,
rank() over(order by success_date) as rnk
from Succeeded
where year(success_date)=2019
order by dat)

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;
30 changes: 30 additions & 0 deletions Problem2_StudentReportByGeography.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Write your MySQL query statement below
--Solution 1

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

--Solution 2 with session variables

select America,Asia,Europe from (
(select @am:=0, @as:=0,@eu:=0)t1,
(select @as:=@as+1 as 'asrnk',name as 'Asia' from student where continent='Asia' order by Asia)t2
right join
(select @am:=@am+1 as 'amrnk',name as 'America' from student where continent='America' order by America)t3 on asrnk=amrnk
left join
(select @eu:=@eu+1 as 'eurnk',name as 'Europe' from student where continent='Europe' order by Europe)t4 on eurnk=amrnk
)
19 changes: 19 additions & 0 deletions Problem3_AvgSalarDepComp.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Write your MySQL query statement below
with compavgcte as (
select concat(year(pay_date),'-',lpad(month(pay_date),2,'0')) as pay_month,
avg(amount) as compavg
from salary
group by 1),
depavgcte as (select e.department_id,
concat(year(pay_date),'-',lpad(month(pay_date),2,'0')) as pay_month,
avg(amount) as depavg
from employee e
inner join salary s on e.employee_id=s.employee_id
group by 1,2)

select d.pay_month,
d.department_id,
case when d.depavg > c.compavg then 'higher'
when d.depavg = c.compavg then 'same'
else 'lower' end as comparison
from depavgcte d inner join compavgcte c on d.pay_month=c.pay_month
4 changes: 4 additions & 0 deletions Problem4_GamePlay1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Write your MySQL query statement below
select player_id, min(event_date) as first_login
from activity
group by player_id