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
13 changes: 13 additions & 0 deletions Problem 1.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 employee_id,experience,salary, sum(salary) over(partition by experience order by salary) as Acccandidates
from Candidates
)

select 'Senior' as experience,count(employee_id) as accepted_candidates
from cte
where experience='Senior' and Acccandidates<=70000
union
select 'Junior' as experience,count(employee_id) as accepted_candidates
from cte
where experience='Junior' and Acccandidates<= (select 70000-ifnull(max(Acccandidates),0) from cte where experience='Senior' and Acccandidates<=70000);
19 changes: 19 additions & 0 deletions Problem 2.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 home_team_id as hid, away_team_id as aid, home_team_goals as htg, away_team_goals as atg
from matches
union all
select away_team_id as hid, home_team_id as aid, away_team_goals as htg, home_team_goals as atg
from matches)


select teams.team_name,count(hid) as matches_played,
sum(case when htg > atg then '3'
when htg = atg then '1'
else 0
end) points,sum(htg) as goal_for,sum(atg) as goal_against ,(sum(htg)-sum(atg)) as goal_diff
from cte
join teams on cte.hid=teams.team_id
group by hid
order by points desc,goal_diff desc,team_name;

9 changes: 9 additions & 0 deletions Problem 3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
-- # Write your MySQL query statement below
select s.name
from SalesPerson s
where s.sales_id not in (
select o.sales_id
from orders o
join company c on o.com_id=c.com_id
where name='Red'
)
14 changes: 14 additions & 0 deletions Problem 4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
with cte as(
select requester_id as id from RequestAccepted
union all
select accepter_id as id from RequestAccepted),

counts as(
select id,count(*) as num
from cte
group by id
)

select id,num from counts
where num=(select max(num) from counts);