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
12 changes: 12 additions & 0 deletions friend-request-ii
Original file line number Diff line number Diff line change
@@ -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;
26 changes: 26 additions & 0 deletions league-statistics
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 11 additions & 0 deletions number-of-senior-junior
Original file line number Diff line number Diff line change
@@ -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);
8 changes: 8 additions & 0 deletions sales-person
Original file line number Diff line number Diff line change
@@ -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);