From 13ac7bff3ad41daea2553be7ac1569eedc6b1ef0 Mon Sep 17 00:00:00 2001 From: anson-nishanth Date: Fri, 27 Dec 2024 00:51:32 -0800 Subject: [PATCH 1/4] Create number-of-senior-junior --- number-of-senior-junior | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 number-of-senior-junior 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); From f1ef7742d38ac7cfb84e3786ceb8372e4a986d65 Mon Sep 17 00:00:00 2001 From: anson-nishanth Date: Fri, 27 Dec 2024 00:52:31 -0800 Subject: [PATCH 2/4] Create league-statistics --- league-statistics | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 league-statistics 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; From f17040b00052d773cd0d6ac841690df8a20f3d42 Mon Sep 17 00:00:00 2001 From: anson-nishanth Date: Fri, 27 Dec 2024 00:53:14 -0800 Subject: [PATCH 3/4] Create sales-person --- sales-person | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 sales-person 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); + From d5f03f35c1bb26908fc4db406db162b67321e631 Mon Sep 17 00:00:00 2001 From: anson-nishanth Date: Fri, 27 Dec 2024 00:54:13 -0800 Subject: [PATCH 4/4] Create friend-request-ii --- friend-request-ii | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 friend-request-ii 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;