Friend Request Acceptance Rate
Preview mode. Log in to edit, run, submit, and save progress.
Friend Request Acceptance Rate
You are given a table of friend request actions. Each row represents either a 'sent' or 'accepted' action between a sender and a receiver. Write a SQL query to find for each sender: the total number of requests sent, the total number accepted, and the acceptance rate (accepted / sent), rounded to 2 decimal places. Senders with zero accepted requests should still appear with an acceptance rate of 0.00. Return the result ordered by sender_id. Note: You can assume that for every 'accepted' row, a corresponding 'sent' row exists for the same sender_id and receiver_id pair. Table: FriendRequests
| Column Name | Type | Description |
|---|---|---|
| sender_id | INT | ID of the user who sent the request |
| receiver_id | INT | ID of the user who received it |
| action | VARCHAR | 'sent' or 'accepted' |
| action_date | DATE | Date of the action |
Examples
Sender 1 sent 2 requests, 1 accepted → rate 0.50. Sender 2 sent 2, 1 accepted → 0.50. Sender 3 sent 1, none accepted → 0.00.
Approach hint
Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.
Common mistake
Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.