diff --git a/Problem1_SeniorJunior.sql b/Problem1_SeniorJunior.sql new file mode 100644 index 0000000..7df9518 --- /dev/null +++ b/Problem1_SeniorJunior.sql @@ -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) \ No newline at end of file diff --git a/Problem2_LeagueStatistics.sql b/Problem2_LeagueStatistics.sql new file mode 100644 index 0000000..87111ae --- /dev/null +++ b/Problem2_LeagueStatistics.sql @@ -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 \ No newline at end of file diff --git a/Problem3_SalesPerson.sql b/Problem3_SalesPerson.sql new file mode 100644 index 0000000..7d1d5f6 --- /dev/null +++ b/Problem3_SalesPerson.sql @@ -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) \ No newline at end of file diff --git a/Problem4_FriendRequestsII.sql b/Problem4_FriendRequestsII.sql new file mode 100644 index 0000000..54eebd9 --- /dev/null +++ b/Problem4_FriendRequestsII.sql @@ -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 \ No newline at end of file