https://leetcode.com/articles/friend-requests-i-overall-acceptance-rate/
The divisor (total number of requests) could be '0' if the table friend_request is empty. So, we have to utilize ifnull
to deal with this special case.
Method 1:
select
round(
ifnull(
(select count(*) from (select distinct requester_id, accepter_id from request_accepted))
/cast((select count(*) from (select distinct sender_id, send_to_id from friend_request)) as float),
0),
2)
as accept_rate;
Method 2:
select round(
ifnull(acc/cast(req as float),0),
2) accept_rate from
(
select count(*) req from
(
select distinct sender_id, send_to_id from friend_request
)) r,
(select count(*) acc from
(
select distinct requester_id, accepter_id from request_accepted
)) a