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 Problem1.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 rsum FROM Candidates
)

SELECT 'Senior' AS experience, COUNT(employee_id) AS accepted_candidates
FROM CTE
WHERE experience = 'Senior' AND rsum <= 70000
UNION
SELECT 'Junior' AS experience, COUNT(employee_id) AS accepted_candidates
FROM CTE
WHERE experience = 'Junior' AND rsum <= (SELECT 70000 - IFNULL(MAX(rsum), 0) FROM CTE WHERE experience = 'Senior' AND rsum <= 70000);
21 changes: 21 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Write your MySQL query statement below
WITH CTE AS (
SELECT home_team_id AS r1, away_team_id AS r2, home_team_goals AS g1, away_team_goals AS g2
FROM Matches
UNION ALL
SELECT away_team_id AS r1, home_team_id AS r2, away_team_goals AS g1, home_team_goals AS g2
FROM Matches
)

SELECT t.team_name, COUNT(c.r1) AS matches_played,
SUM(
CASE
WHEN c.g1 > c.g2 THEN 3
WHEN c.g1 = c.g2 THEN 1
ELSE 0
END) AS points, SUM(c.g1) AS goal_for, SUM(c.g2) AS goal_against, SUM(c.g1) - SUM(c.g2) AS goal_diff
FROM Teams t
INNER JOIN CTE c
ON t.team_id = c.r1
GROUP BY c.r1
ORDER BY points DESC, goal_diff DESC, team_name ASC;
5 changes: 5 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Write your MySQL query statement below
SELECT name FROM SalesPerson WHERE sales_id NOT IN
(SELECT o.sales_id FROM Orders o
LEFT JOIN Company c ON o.com_id = c.com_id
WHERE c.name = 'RED');
9 changes: 9 additions & 0 deletions Problem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below
SELECT id, COUNT(*) AS num
FROM
(SELECT requester_id AS id FROM RequestAccepted
UNION ALL
SELECT accepter_id AS id FROM RequestAccepted) AS combined
GROUP BY id
ORDER BY num DESC
LIMIT 1;