diff --git a/friend-request-ii b/friend-request-ii new file mode 100644 index 0000000..c0b6d8e --- /dev/null +++ b/friend-request-ii @@ -0,0 +1,12 @@ +WITH CTE AS +(select accepter_id as id ,count(*) as no_of_time from RequestAccepted +group by accepter_id +union all +select requester_id as id ,count(*) as no_of_time from RequestAccepted +group by requester_id) + +SELECT ID, +SUM(NO_OF_TIME) AS NUM +FROM CTE +GROUP BY ID +ORDER BY NUM DESC LIMIT 1; diff --git a/league-statistics b/league-statistics new file mode 100644 index 0000000..0fedb19 --- /dev/null +++ b/league-statistics @@ -0,0 +1,26 @@ +with CTE AS ( +select home_team_id as r1,home_team_goals as g1,away_team_goals as g2 +from +matches +union all +select away_team_id as r1,away_team_goals as g1,home_team_goals g2 +from +matches +) +select +t.team_name as 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 +join +CTE c +on t.team_id = c.r1 +group by t.team_id +order by points desc,goal_diff desc,team_name; diff --git a/number-of-senior-junior b/number-of-senior-junior new file mode 100644 index 0000000..96868d4 --- /dev/null +++ b/number-of-senior-junior @@ -0,0 +1,11 @@ +with CTE1 AS ( +SELECT employee_id , experience,salary, sum(salary) over(partition by experience order by salary) cummulative_salary +from candidates +), +CTE2 AS ( +SELECT coalesce(70000 - coalesce(max(cummulative_salary),0),0) remaining from CTE1 where cummulative_salary <70000 and experience='Senior' +) + +select 'Senior' as experience,count(distinct employee_id) as accepted_candidates from CTE1 WHERE cummulative_salary <70000 and experience='Senior' +union +select 'Junior' as experience ,count(distinct employee_id) as accepted_candidates from CTE1 WHERE experience='Junior' and cummulative_salary < (select remaining from CTE2); diff --git a/sales-person b/sales-person new file mode 100644 index 0000000..79af4e2 --- /dev/null +++ b/sales-person @@ -0,0 +1,8 @@ +WITH RED_SALES AS ( +select o.sales_id from +orders o +join company c +on o.com_id = c.com_id +where c.name='RED') +SELECT NAME FROM SALESPERSON WHERE SALES_ID NOT IN (SELECT SALES_ID FROM RED_SALES); +