Task
At Meta, a Product Growth Analyst may look at friend request acceptance as part of the AARRR activation and engagement funnel for Facebook social graph growth. Using a single table of friend requests, write a SQL query to find the sender with the highest acceptance rate.
Requirements
- Compute each
sender_id's acceptance rate as:
accepted requests / total requests sent
- Only treat rows with
status = 'accepted' as accepted.
- Return the sender with the highest acceptance rate.
- Include the columns
sender_id, accepted_requests, total_requests, and acceptance_rate.
- Order by
acceptance_rate descending, then sender_id ascending, and return the top row.
Table Definition
friend_requests
| column | type | description |
|---|
| request_id | INT | Unique request identifier |
| sender_id | INT | User who sent the friend request |
| receiver_id | INT | User who received the friend request |
| status | VARCHAR(20) | Request status such as accepted, pending, rejected, or NULL |
| request_date | DATE | Date the request was created |
Sample Data
| request_id | sender_id | receiver_id | status | request_date |
|---|
| 8 | 104 | 206 | accepted | 2024-01-08 |
| 2 | 101 | 202 | pending | 2024-01-02 |
| 11 | 106 | 209 | accepted | 2024-01-11 |
| 1 | 101 | 201 | accepted | 2024-01-01 |
| 5 | 103 | 204 | rejected | 2024-01-05 |
| 10 | 105 | 208 | pending | 2024-01-10 |
| 3 | 101 | 203 | rejected | 2024-01-03 |
| 6 | 103 | 205 | pending | 2024-01-06 |
| 9 | 105 | 207 | NULL | 2024-01-09 |
| 4 | 102 | 201 | accepted | 2024-01-04 |
| 7 | 104 | 201 | accepted | 2024-01-07 |
| 12 | 106 | 210 | accepted | 2024-01-12 |
Expected Output
| sender_id | accepted_requests | total_requests | acceptance_rate |
|---|
| 104 | 2 | 2 | 1.0000 |