SQL计算留存率指标

select *,CONCAT(ROUND(100*ciriliucun/huoyue,2),'%') ciri from(
select DATE_FORMAT(a.logindate,'%Y-%m-%d') time,count(DISTINCT(a.userId)) huoyue,count(DISTINCT(b.userId)) ciriliucun from log a LEFT JOIN log b on a.userId = b.userId and
 STR_TO_DATE(b.logindate,'%Y-%m-%d') = DATE_FORMAT(DATE_ADD(STR_TO_DATE(a.logindate,'%Y-%m-%d'),INTERVAL 1 DAY),'%Y-%m-%d')
	GROUP BY time
) p LIMIT 7;
发布了467 篇原创文章 · 获赞 215 · 访问量 19万+

猜你喜欢

转载自blog.csdn.net/qq_44868502/article/details/104979781