diff --git a/Problem 1.sql b/Problem 1.sql new file mode 100644 index 0000000..3b5b956 --- /dev/null +++ b/Problem 1.sql @@ -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); \ No newline at end of file diff --git a/Problem 2.sql b/Problem 2.sql new file mode 100644 index 0000000..2700f32 --- /dev/null +++ b/Problem 2.sql @@ -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; + diff --git a/Problem 3.sql b/Problem 3.sql new file mode 100644 index 0000000..5d5bc6e --- /dev/null +++ b/Problem 3.sql @@ -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' +) diff --git a/Problem 4.sql b/Problem 4.sql new file mode 100644 index 0000000..cb42f41 --- /dev/null +++ b/Problem 4.sql @@ -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); +