计算留存率和留存数的SQL要怎么写呢?

Vince Yan 2018-08-20 11:16:35

如图所示,谢谢大神们!
...全文
3584 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
乔木zzz 2019-12-23
  • 打赏
  • 举报
回复
select *, concat(round(100 * 次日留存用户数/活跃用户数, 2), '%') 次日留存率, concat(round(100 * 三日留存用户数/活跃用户数, 2), '%') 三日留存率, concat(round(100 * 七日留存用户数/活跃用户数, 2), '%') 七日留存率 from ( select a.dayno 日期, count(distinct a.uid) 活跃用户数, count(distinct b.uid) 次日留存用户数, count(distinct c.uid) 三日留存用户数, count(distinct d.uid) 七日留存用户数 from act_user_info a left join act_user_info b on a.uid = b.uid and b.dayno = a.dayno + 1 left join act_user_info c on a.uid = c.uid and c.dayno = a.dayno + 3 left join act_user_info d on a.uid = d.uid and d.dayno = a.dayno + 7 group by a.dayno ) p;
MW_long 2018-08-21
  • 打赏
  • 举报
回复

这个是回头人数
select a.fdate as actfdate, b.fdate as backfdate, count(a.uid) as backCnt from
(SELECT fdate, uid from table where fdate >= startA and fdate < endA) as a,
(SELECT fdate, uid from table where fdate >= startB and fdate < endB) as b
where a.uid = b.uid and a.fdate < b. fdate group by actfdate, backfdate

这是当天活跃
select fdate, count(uid) as actCnt from table where fdate >= startA and fdate < endA group by fdate

这两个表连接 就求出回头率了

还有表结构, uid 为什么用string ?一般不是int 或者bigint吗? 然后 启动时长, 一天才 8w多秒, 为什么用bigint, 启动次数也是, 还有日期, 为什么用string? 不用int?














75闪光雷 2018-08-20
  • 打赏
  • 举报
回复
计算两个数据相除 select (select sum(a) from xx)/(select sum(b) from xx) from dual; 格式化为两位小数decimal=2 select convert(4545.1366,decimal); 仅供参考,你自己写出来的印象会深一点。 不提供完整sql

56,675

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧