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
12 changes: 12 additions & 0 deletions 1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Write your MySQL query statement below
with cte as (
select employee_id, experience, sum(salary) over (partition by experience order by salary, employee_id) as ru_sum
from Candidates
)
Select 'Senior' as experience, count(employee_id) as accepted_candidates
from cte where experience ='senior' and ru_sum<=70000
union
Select 'Junior' as experience, count(employee_id) as accepted_candidates
from cte where experience ='junior' and ru_sum<=(
Select 70000 - ifnull(max(ru_sum),0)
from cte where experience ='senior' and ru_sum<=70000)
26 changes: 26 additions & 0 deletions 2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Write your MySQL query statement below
with cte as
(
select home_team_id as t, home_team_goals as goal, away_team_goals as away,
case
when home_team_goals > away_team_goals then 3
when home_team_goals < away_team_goals then 0
else 1
end as points
from Matches
union all
select away_team_id as t, away_team_goals as goal, home_team_goals as away,
case
when away_team_goals > home_team_goals then 3
when away_team_goals < home_team_goals then 0
else 1
end as points
from Matches
)
select t1.team_name, count(t1.team_id) as matches_played, sum(cte.points) as points,
sum(cte.goal) goal_for,sum(cte.away)goal_against, sum(cte.goal) - sum(cte.away) as goal_diff
from Teams t1
Join cte
on t1.team_id = cte.t
group by t1.team_id
order by points desc, goal_diff desc, team_name
12 changes: 12 additions & 0 deletions 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Write your MySQL query statement below
with cte as (Select s.sales_id, o.order_id, s.name, o.com_id from SalesPerson s
left join Orders o
on o.sales_id = s.sales_id)
select name
from SalesPerson
where name not in (
select cte.name from cte
left join Company c
on cte.com_id=c.com_id
where c.name ='RED'
)
12 changes: 12 additions & 0 deletions 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
with cte as (select requester_id as r1
from RequestAccepted
union all
select accepter_id as r1
from RequestAccepted
)

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