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
10 changes: 10 additions & 0 deletions FriendRequests2.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# 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 id , COUNT(id) AS 'num' FROM CTE GROUP BY id ORDER BY num DESC limit 1;
36 changes: 36 additions & 0 deletions LeagueStatistics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
WITH
Scores AS (
SELECT
home_team_id AS team_id,
CASE
WHEN home_team_goals > away_team_goals THEN 3
WHEN home_team_goals < away_team_goals THEN 0
ELSE 1
END AS score,
home_team_goals AS goals,
away_team_goals AS away_goals
FROM Matches
UNION ALL
SELECT
away_team_id AS team_id,
CASE
WHEN home_team_goals > away_team_goals THEN 0
WHEN home_team_goals < away_team_goals THEN 3
ELSE 1
END AS score,
away_team_goals AS goals,
home_team_goals AS away_goals
FROM Matches
)
SELECT
team_name,
COUNT(1) AS matches_played,
SUM(score) AS points,
SUM(goals) AS goal_for,
SUM(away_goals) AS goal_against,
(SUM(goals) - SUM(away_goals)) AS goal_diff
FROM
Scores AS s
JOIN Teams AS t ON s.team_id = t.team_id
GROUP BY s.team_id
ORDER BY points DESC, goal_diff DESC, team_name;
50 changes: 50 additions & 0 deletions NumberofSeniors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
with s as (
select
employee_id,
sum(salary) over(
order by
salary
) cur
from
Candidates
where
experience = 'Senior'
),
j as (
select
employee_id,
ifnull(
(
select
max(cur)
from
s
where
cur <= 70000
),
0
) + sum(salary) over(
order by
salary
) cur
from
Candidates
where
experience = 'Junior'
)
select
'Senior' experience,
count(employee_id) accepted_candidates
from
s
where
cur <= 70000
union
all
select
'Junior' experience,
count(employee_id) accepted_candidates
from
j
where
cur <= 70000;
2 changes: 2 additions & 0 deletions SalesPerson.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SELECT name FROM salesperson WHERE sales_id NOT IN(
SELECT o.sales_id FROM orders o JOIN company C on o.com_id = c.com_id WHERE c.name='RED');