sql 工作记录

2020-07-14  本文已影响0人  SilasChen

接到老板通知,要我统计几个数据。

1,近三个月每个月登录次数少于2的有多少人,

2,近六个月每个月登录次数少于2的有多少人。

想了一下,基本思路:

    将数据按月份,用户分组,就能得到用户每个月的登录次数。然后筛选出大于2的人数,那剩下的就是小于2的人数了。

select distinct userid

from qliksense_users

except

select distinct t1.userid

from (

SELECT userid,to_char(accesstime,'YY') as y,to_char(accesstime, 'MM') as m

FROM app_user_action_log

WHERE action=0  And accesstime >date_trunc('month', CURRENT_DATE) - INTERVAL '6 month' 

GROUP BY 2,3,userid

having count(id)>=5 ) T1   

3,近三个月未登录过的用户?

  筛选出近三个月登录的用户,再从用户表剔除这些,剩下的就是未登录过的。

 select userid from qliksense_users

except

select userid from app_user_action_log where action=0 and accesstime>CURRENT_DATE- INTERVAL'3 month'

上一篇 下一篇

猜你喜欢

热点阅读