首页 > 数据库技术 > 详细

metabase一个sql统计

时间:2020-07-25 19:37:30      阅读:114      评论:0      收藏:0      [点我收藏+]
select ma.cnt1 as "上周注册用户总数",ma.cnt2 as "上周活跃用户数",ma.cnt3 as "本周活跃用户数",cast (ma.cnt3 as double)/ma.cnt1 as "新用户留存率",cast(ma.cnt3 as double)/ma.cnt2 as "老用户留存率" from
 (select count(1) as cnt1 ,
        sum((case when 
              exists (select 1 from strategy.fcoin_settledetails b where b.settledate between cast(date_add(day,-5-day_of_week(current_date),{{s_time}})as timestamp)
                                                                        and cast(date_add(day,-5-day_of_week(current_date),{{e_time}})as timestamp)
                                                                        and b.userid = a.id)
                  then 1 
                  else 0 end)) as cnt2,
        sum((case when 
              exists (select 1 from strategy.fcoin_settledetails b where b.settledate between cast({{s_time}} as timestamp)
                                                                        and cast({{e_time}} as timestamp)
                                                                        and b.userid = a.id)
                  then 1 
                  else 0 end)) as cnt3  
   from cptrd.account_users a 
  where create_time between cast(date_add(day,-5-day_of_week(current_date),{{s_time}})as timestamp) 
   and cast(date_add(day,-5-day_of_week(current_date),{{e_time}})as timestamp) )ma

 

metabase一个sql统计

原文:https://www.cnblogs.com/5sdba-notes/p/13375835.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!