metabase一個sql統計


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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM