GuilinDev

Lc0597

05 August 2008

597. Friend Requests I: Overall Acceptance Rate

Table: FriendRequest

+—————-+———+ | Column Name | Type | +—————-+———+ | sender_id | int | | send_to_id | int | | request_date | date | +—————-+———+ There is no primary key for this table, it may contain duplicates. This table contains the ID of the user who sent the request, the ID of the user who received the request, and the date of the request.

Table: RequestAccepted

+—————-+———+ | Column Name | Type | +—————-+———+ | requester_id | int | | accepter_id | int | | accept_date | date | +—————-+———+ There is no primary key for this table, it may contain duplicates. This table contains the ID of the user who sent the request, the ID of the user who received the request, and the date when the request was accepted.

1
2
3
4
5
6
7
8
9
SELECT COALESCE(
    (ROUND(
        (SELECT COUNT(DISTINCT requester_id, accepter_id)
         FROM RequestAccepted)
        /
        (SELECT COUNT(DISTINCT sender_id, send_to_id)
        FROM FriendRequest)
    , 2))
, 0.00) AS accept_rate;