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
6 changes: 6 additions & 0 deletions Problem1.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
WITH CTE AS (
SELECT employee_id, experience, salary, 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)
18 changes: 18 additions & 0 deletions Problem2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
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 home_team_id as r2, away_team_id as r1, home_team_goals as g2, away_team_goals as g1
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, t.team_name;
4 changes: 4 additions & 0 deletions Problem3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SELECT name from SalesPerson where sales_id NOT IN ( Select DISTINCT o.sales_id
From Orders o
Join Company c ON o.com_id = c.com_id
where c.name = 'RED')
8 changes: 8 additions & 0 deletions Problem4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WITH CTE AS(
Select requester_id as id from RequestAccepted
UNION ALL
Select accepter_id as id from RequestAccepted)
Select id, count(id) as 'num' from CTE
group by id
order by num desc
LIMIT 1