当前位置:网站首页>每日sql:求好友申请通过率

每日sql:求好友申请通过率

2022-08-11 05:35:00 吃再多糖也不长胖

每日sql :求好友申请通过率

背景

模拟两张表。1为好友申请表,2为申请通过表

问题1:好友申请通过率

ddl

Create table If Not Exists friend_request ( sender_id INT NOT NULL, send_to_id INT NULL, request_date DATE NULL);Create table If Not Exists request_accepted ( requester_id INT NOT NULL, accepter_id INT NULL, accept_date DATE NULL);insert into friend_request (sender_id, send_to_id, request_date) values (1, 2, '2016/06/01');insert into friend_request (sender_id, send_to_id, request_date) values (1, 3, '2016/06/01');insert into friend_request (sender_id, send_to_id, request_date) values (1, 4, '2016/06/01');insert into friend_request (sender_id, send_to_id, request_date) values (2, 3, '2016/06/02');insert into friend_request (sender_id, send_to_id, request_date) values (3, 4, '2016/06/09');insert into request_accepted (requester_id, accepter_id, accept_date) values (1, 2, '2016/06/03');insert into request_accepted (requester_id, accepter_id, accept_date) values (1, 3, '2016/06/08');insert into request_accepted (requester_id, accepter_id, accept_date) values (2, 3, '2016/06/08');insert into request_accepted (requester_id, accepter_id, accept_date) values (3, 4, '2016/06/09');insert into request_accepted (requester_id, accepter_id, accept_date) values (3, 4, '2016/06/10');

在这里插入图片描述

sql

select  round(  (select count(*) from (select distinct requester_id,accepter_id from request_accepted) as b) /  (select   count(*) from (select distinct sender_id,send_to_id from friend_request) as a) ,2)

在这里插入图片描述

原网站

版权声明
本文为[吃再多糖也不长胖]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_43859562/article/details/122880611