diff --git a/Friend_Request.sql b/Friend_Request.sql new file mode 100644 index 0000000..ecbd1ad --- /dev/null +++ b/Friend_Request.sql @@ -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; \ No newline at end of file diff --git a/League_Statistics.sql b/League_Statistics.sql new file mode 100644 index 0000000..84ade9b --- /dev/null +++ b/League_Statistics.sql @@ -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; \ No newline at end of file diff --git a/Number_of_seniors_Juniors.sql b/Number_of_seniors_Juniors.sql new file mode 100644 index 0000000..beeb537 --- /dev/null +++ b/Number_of_seniors_Juniors.sql @@ -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; \ No newline at end of file diff --git a/Sales_Person.sql b/Sales_Person.sql new file mode 100644 index 0000000..d8c7001 --- /dev/null +++ b/Sales_Person.sql @@ -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 \ No newline at end of file