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
19 changes: 19 additions & 0 deletions Problem1_SeniorJunior.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Write your MySQL query statement below
with cte as
(select
*,
sum(salary) over (partition by experience order by salary,employee_id) as rsum
from candidates
)

select
'Senior' as experience,
count(employee_id) as accepted_candidates
from cte
where experience='Senior' and rsum <= 70000
union all
select 'Junior' as experience,
count(employee_id) as accepted_candidates
from cte
where experience ='Junior'
and rsum <= (select 70000-coalesce(max(rsum),0) from cte where experience ='Senior' and rsum <= 70000)
23 changes: 23 additions & 0 deletions Problem2_LeagueStatistics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Write your MySQL query statement below
with cte as (
select home_team_id as 'id',home_team_goals as goal_for,away_team_goals as goal_against
from matches
union all
select away_team_id as 'id',away_team_goals as goal_for,home_team_goals as goal_against
from matches
)

#select * from cte

select t.team_name,
count(c.id) as matches_played,
sum(case when goal_for > goal_against then 3
when goal_for = goal_against then 1
else 0 end) as points,
sum(c.goal_for) as goal_for,
sum(c.goal_against) as goal_against,
sum(c.goal_for)- sum(c.goal_against) as goal_diff
from cte c
inner join Teams t on c.id=t.team_id
group by id
order by points desc,goal_diff desc,t.team_name
10 changes: 10 additions & 0 deletions Problem3_SalesPerson.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Write your MySQL query statement below

with cte as
(select distinct sales_id
from orders o inner join company c on o.com_id=c.com_id
where name='RED')

select name
from salesperson
where sales_id not in (select sales_id from cte)
13 changes: 13 additions & 0 deletions Problem4_FriendRequestsII.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Write your MySQL query statement below
with cte as
(select requester_id as id
from requestAccepted
union all
select accepter_id as id
from requestAccepted)

select distinct id,
count(id) as num
from cte
group by id
order by 2 desc limit 1