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
2 changes: 2 additions & 0 deletions Friend_Request.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
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;
8 changes: 8 additions & 0 deletions League_Statistics.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
WITH CTE AS (
SELECT home_team_id as id ,home_team_goals as hg, away_team_goals as ag from matches
union all
select away_team_id as id, away_team_goals as hg, home_team_goals as ag from matches
), POINTS AS (
select id,case when hg>ag then 3
when hg=ag then 1 else 0 end as points,hg,ag from CTE)
select teams.team_name,count(id)as matches_played,sum(points) as points, sum(hg) as goal_for, sum(ag) as goal_against,sum(hg)- sum(ag) as goal_diff from points left join teams on teams.team_id = points.id group by id order by points desc, goal_diff desc, team_name;
30 changes: 30 additions & 0 deletions Number_of_seniors_Juniors.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
with seniors as
(
select employee_id,
70000 - rolling_sum as budget_left
from
(select *,
sum(salary) over(order by salary asc) as rolling_sum
from Candidates
where experience = 'Senior') a
where rolling_sum <= 70000
),

juniors as
(
select a.employee_id
from
(select *,
sum(salary) over(order by salary asc) as rolling_sum
from Candidates
where experience = 'Junior') a
where rolling_sum <= (select coalesce(min(budget_left), 70000) from seniors)
)

select 'Senior' as experience,
coalesce(count(employee_id), 0) as accepted_candidates
from seniors
union all
select 'Junior' as experience,
coalesce(count(employee_id), 0) as accepted_candidates
from juniors;
4 changes: 4 additions & 0 deletions Sales_Person.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
select salesperson.name
from orders o join company c on (o.com_id = c.com_id and c.name = 'RED')
right join salesperson on salesperson.sales_id = o.sales_id
where o.sales_id is null