Posted by gurpreet, Oct. 29, 2021, 8:37 p.m.
SQL#97
I have the following solution:
WITH sender as
(
SELECT sender_id as id,
count(distinct recipient_id) as cnt
FROM accepted_request
GROUP BY id
),
recipient as
(
SELECT recipient_id as id,
count(distinct sender_id) as cnt
FROM accepted_request
GROUP BY id
),
cumulative as
(
select * from sender
union
select * from recipient
),
top as
(
SELECT id,
sum(cnt) as count_id
from cumulative
group by id
)
select id from top
order by count_id desc
limit 1
I am trying to find the mistake in this code, can anyone help? Appreciate it, thanks!
WITH sender as
(
SELECT sender_id as id,
count(distinct recipient_id) as cnt
FROM accepted_request
GROUP BY id
),
recipient as
(
SELECT recipient_id as id,
count(distinct sender_id) as cnt
FROM accepted_request
GROUP BY id
),
cumulative as
(
select * from sender
union
select * from recipient
),
top as
(
SELECT id,
sum(cnt) as count_id
from cumulative
group by id
)
select id from top
order by count_id desc
limit 1
I am trying to find the mistake in this code, can anyone help? Appreciate it, thanks!