Forum

Posted by Luming, Oct. 29, 2021, 6:29 p.m.

SQL 96

For this one, why we only apply DISTINCT to sender_id here?
WITH acceptance AS
(SELECT COUNT(*) as accept_cnt
FROM
(SELECT DISTINCT sender_id,recipient_id
FROM accepted_request) sub
),
request AS
(SELECT COUNT(*) as request_cnt
FROM
(SELECT DISTINCT sender_id,recipient_id
FROM friend_request) sub
)
SELECT a.accept_cnt *1.0/r.request_cnt as acceptance_rate
FROM acceptance as a,
request as r

Answers

DISTINCT keyword applies to all columns mentioned after it, so basically in our query, it is applied to both the columns, i.e. sender_id and also recipient_id
SQLPad user avatar

gurpreet (26)

Oct. 29, 2021, 8:02 p.m.

Hey @luming, the distinct deduplicates as people can accidentally accept the same friend requests multiple times. e.g., on their computer, and later on their device. Before the multi-platform has synced up yet.
SQLPad user avatar

Leon (949)

Nov. 1, 2021, 5:27 p.m.