-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAcceptance Rate By Date
43 lines (38 loc) · 1.19 KB
/
Acceptance Rate By Date
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
What is the overall friend acceptance rate by date? Your output should have the rate of acceptances by the date the request was sent. Order by the earliest date to latest.
Assume that each friend request starts by a user sending (i.e., user_id_sender) a friend request to another user (i.e., user_id_receiver) that's logged in the table with action = 'sent'. If the request is accepted, the table logs action = 'accepted'. If the request is not accepted, no record of action = 'accepted' is logged.
Table: fb_friend_requests
fb_friend_requests
Preview
user_id_sender:
varchar
user_id_receiver:
varchar
date:
datetime
action:
varchar
--acceptance rate = # accepted / # sent
SELECT
a.date,
count(b.user_id_receiver)/count(a.user_id_sender) ::float as
acceptance_rate
FROM(
SELECT
user_id_sender,
user_id_receiver,
date,
action
FROM fb_friend_requests
WHERE action='sent') a
LEFT JOIN (
SELECT
user_id_sender,
user_id_receiver,
date,
action
FROM fb_friend_requests
WHERE action='accepted') b
on b.user_id_sender = a.user_id_sender
and b.user_id_receiver= a.user_id_receiver
GROUP BY a.date
ORDER BY a.date