当前位置:网站首页>Daily sql: request for friend application pass rate

Daily sql: request for friend application pass rate

2022-08-11 07:14:00 Eating too much sugar will not gain weight

每日sql :Ask friends applicants

背景

Simulate the two tables.1As a friend form,2For application through the table

问题1:Buddy applicants

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)

在这里插入图片描述

原网站

版权声明
本文为[Eating too much sugar will not gain weight]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/223/202208110517396334.html