- ***************************************************************************************
- *********************************************************************************************
- *******************************************************************
Table: friend_request
Friend request table
col_name | col_type --------------+-------------------------- sender_id | bigint recipient_id | bigint request_dt | date
Sample results
id -------------- 1000027
Solution postgres
SELECT recipient_id
FROM friend_request
WHERE request_dt >= '2021-01-01'
AND request_dt < '2021-02-01'
GROUP BY recipient_id
ORDER BY COUNT(DISTINCT sender_id) DESC
LIMIT 1;
Explanation
This query retrieves the recipient_id from the friend_request table for the requests made in January 2021. It groups the recipient_id by the number of distinct sender_id, orders them in descending order, and only returns the top result. This means that it will return the recipient who received the most friend requests from unique senders in January 2021.
Copied
Expected results
Your results