Task
At Meta, growth analysts often inspect invite and connection quality as part of the AARRR activation funnel for surfaces like Facebook Groups. You are given a table of friend request events and need to identify which sender has the highest acceptance rate.
Write a SQL query to find the user with the highest acceptance rate, defined as:
accepted requests sent / total non-null-status requests sent
Requirements
- Compute acceptance rate at the sender_id level.
- Count only rows where
status is not NULL in the denominator.
- Treat
status = 'accepted' as an accepted request.
- Return the sender with the highest acceptance rate.
- Include these output columns:
sender_id, accepted_requests, total_requests, acceptance_rate.
- Order by
acceptance_rate descending, then sender_id ascending, and return the top row only.
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 outcome such as accepted, declined, pending, or NULL |
Sample Data
| request_id | sender_id | receiver_id | status |
|---|
| 1 | 103 | 201 | accepted |
| 2 | 101 | 202 | declined |
| 3 | 104 | 203 | pending |
| 4 | 101 | 204 | accepted |
| 5 | 102 | 205 | accepted |
| 6 | 103 | 206 | accepted |
Expected Output
| sender_id | accepted_requests | total_requests | acceptance_rate |
|---|
| 103 | 2 | 2 | 1.0000 |