题解 | #查询多列#
计算用户的平均次日留存率
http://www.nowcoder.com/practice/126083961ae0415fbde061d7ebbde453
【SQL牛客在线编程答案】
【01】
select device_id, gender, age, university from user_profile;
[次日平均留存率]
select count(distinct b.device_id,b.date)/count(distinct a.device_id,a.date) as avg_ret
from question_practice_detail as a
left join question_practice_detail as b
on a.device_id = b.device_id and datediff(b.date,a.date)=1;