0
点赞
收藏
分享

微信扫一扫

LeetCode(数据库)- 好友申请l:总体通过率


题目链接:​​点击打开链接​​


题目大意:略。


解题思路:1/0, 0/0 结果都为 NULL。


AC 代码

-- 解决方案(1)
WITH t1 AS(SELECT 1 id, COUNT(DISTINCT requester_id, accepter_id) up FROM RequestAccepted),
t2 AS(SELECT 1 id, COUNT(DISTINCT sender_id, send_to_id) down FROM FriendRequest)

SELECT IF(down = 0, 0.00, ROUND(up/down, 2)) accept_rate
FROM t1, t2
WHERE t1.id = t2.id

-- 解决方案(2)
select
round(
ifnull(
(select count(*) from (select distinct requester_id, accepter_id from request_accepted) as A)
/
(select count(*) from (select distinct sender_id, send_to_id from friend_request) as B),
0)
, 2) as accept_rate;


举报

相关推荐

0 条评论