Friend Requests I: Overall Acceptance Rate - Problem
You are given two tables representing a social network's friend request system.
Table: FriendRequest
sender_id: ID of the user who sent the requestsend_to_id: ID of the user who received the requestrequest_date: Date when the request was sent
Table: RequestAccepted
requester_id: ID of the user who sent the requestaccepter_id: ID of the user who received the requestaccept_date: Date when the request was accepted
Find the overall acceptance rate of friend requests, calculated as the number of acceptances divided by the number of requests. Return the result rounded to 2 decimal places.
Important Notes:
- Both tables may contain duplicates - count unique request/acceptance pairs only
- Accepted requests don't need to exist in the FriendRequest table
- If there are no requests, return 0.00
Table Schema
| Column Name | Type | Description |
|---|---|---|
sender_id
|
int | ID of user sending friend request |
send_to_id
|
int | ID of user receiving friend request |
request_date
|
date | Date when request was sent |
| Column Name | Type | Description |
|---|---|---|
requester_id
|
int | ID of user who sent the accepted request |
accepter_id
|
int | ID of user who accepted the request |
accept_date
|
date | Date when request was accepted |
Input & Output
| sender_id | send_to_id | request_date |
|---|---|---|
| 1 | 2 | 2016-06-01 |
| 1 | 3 | 2016-06-01 |
| 1 | 4 | 2016-06-01 |
| 2 | 3 | 2016-06-02 |
| 3 | 4 | 2016-06-09 |
| requester_id | accepter_id | accept_date |
|---|---|---|
| 1 | 2 | 2016-06-03 |
| 1 | 3 | 2016-06-08 |
| 2 | 3 | 2016-06-08 |
| 3 | 4 | 2016-06-09 |
| accept_rate |
|---|
| 0.80 |
There are 5 distinct friend requests and 4 distinct acceptances. The acceptance rate is 4/5 = 0.80 or 80%.
| sender_id | send_to_id | request_date |
|---|
| requester_id | accepter_id | accept_date |
|---|---|---|
| 1 | 2 | 2016-06-03 |
| accept_rate |
|---|
| 0.00 |
When there are no friend requests, the acceptance rate should be 0.00 even if there are some acceptances recorded.
| sender_id | send_to_id | request_date |
|---|---|---|
| 1 | 2 | 2016-06-01 |
| 1 | 2 | 2016-06-02 |
| requester_id | accepter_id | accept_date |
|---|---|---|
| 1 | 2 | 2016-06-03 |
| 1 | 2 | 2016-06-04 |
| accept_rate |
|---|
| 1.00 |
Even though there are duplicate entries, we count only 1 distinct request (1→2) and 1 distinct acceptance (1→2), giving a rate of 1/1 = 1.00.
Constraints
-
1 ≤ sender_id, send_to_id ≤ 1000 -
1 ≤ requester_id, accepter_id ≤ 1000 - Tables may contain duplicate records
- Result should be rounded to 2 decimal places