[SQL] Given two tables Friend_request (requester_id, sent_to_id , time) Request_accepted (acceptor_id, requestor_id, time) Find the overall acceptance rate of requests.

Data Science Interview QuestionsCategory: Data Science[SQL] Given two tables Friend_request (requester_id, sent_to_id , time) Request_accepted (acceptor_id, requestor_id, time) Find the overall acceptance rate of requests.
2 Answers
MockInterview Staff answered 10 months ago

1. Define how long you have to wait before a friend request is considered rejected (e.g. 1 week)
2. Exclude the most recent data, up to the length in 1
3. Compute answer as count(Request_accepted)/count(Friend_request)
Source

Leo Liu answered 1 month ago

 SELECT round( 100 * count( DISTINCT total.requestor_id) / count(acc.requestor_is), 2) AS acceptance_rate
FROM friend_request total LEFT JOIN request_accepted acc
ON (total.requestor_id = acc.requestor_id AND total. send_to_id = acc.acceptor_id)
WHERE DATEDIFF(IFNULL(acc.time, total_time) , total.time) <= 7
AND DATEDIFF(SYSDATE, total.time) > 30

Your Answer