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
7 changes: 7 additions & 0 deletions Prb1 Seniors & Juniors
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Write your MySQL query statement below
WITH CTE AS (SELECT employee_id, experience, SUM(salary) OVER(PARTITION BY experience ORDER BY salary,employee_id ASC) AS RN FROM Candidates)

SELECT 'Senior' AS experience, COUNT(employee_id) AS accepted_candidates FROM CTE WHERE experience = 'Senior' AND RN < 70000
UNION
SELECT 'Junior' AS experience, COUNT(employee_id) AS accepted_candidates FROM CTE WHERE experience = 'Junior' AND RN < (SELECT 70000 - IFNULL(MAX(RN),0) FROM CTE WHERE experience = 'Senior' AND RN < 70000)

20 changes: 20 additions & 0 deletions Prb2 League Statistics
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Write your MySQL query statement below
WITH CTE AS(
SELECT m1.home_team_id AS 'id', m1.home_team_goals AS 'hg',
m1.away_team_goals AS 'ag' FROM Matches m1
UNION ALL
SELECT m2.away_team_id AS 'id', m2.away_team_goals AS 'hg',
m2.home_team_goals AS 'ag' FROM Matches m2
)

-- SELECT * FROM CTE
SELECT a.team_name, COUNT(c.id) AS 'matches_played', SUM(
CASE
WHEN c.hg > c.ag THEN 3
WHEN c.hg = c.ag THEN 1
ELSE 0
END
) AS 'points', SUM(c.hg) AS 'goal_for', SUM(c.ag) AS 'goal_against',
SUM(c.hg) - SUM(c.ag) AS 'goal_diff'
FROM Teams a LEFT JOIN CTE c ON a.team_id = c.id GROUP BY c.id
ORDER BY points DESC, goal_diff DESC, a.team_name
9 changes: 9 additions & 0 deletions Prb3
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Write your MySQL query statement below
select s.name
from SalesPerson s
where s.name not in
(select s.name
from SalesPerson s
left join Orders o on s.sales_id = o.sales_id
left join Company c on o.com_id = c.com_id
where c.name = 'Red')
7 changes: 7 additions & 0 deletions Prb4 Friend Request
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Write your MySQL query statement below
with base as(select requester_id id from RequestAccepted
union all
select accepter_id id from RequestAccepted)


select id, count(*) num from base group by 1 order by 2 desc limit 1