diff --git a/1.sql b/1.sql new file mode 100644 index 0000000..c29865e --- /dev/null +++ b/1.sql @@ -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) \ No newline at end of file diff --git a/2.sql b/2.sql new file mode 100644 index 0000000..a688b0b --- /dev/null +++ b/2.sql @@ -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 \ No newline at end of file diff --git a/3.sql b/3.sql new file mode 100644 index 0000000..f328ca7 --- /dev/null +++ b/3.sql @@ -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' +) \ No newline at end of file diff --git a/4.sql b/4.sql new file mode 100644 index 0000000..8f4c588 --- /dev/null +++ b/4.sql @@ -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 \ No newline at end of file