mysql 90天以内_mysql-collect_set()仅当用户超过过去90天时,从过去90天开始每天收集不同的用户...

目前,我可以收集所有活跃的用户:

with aux as(

select date

,collect_set(user_id) over(

partition by feature

order by cast(timestamp(date) as float)

range between (-90*60*60*24) following and 0 preceding

) as user_id

,feature

--

from (

select data

,feature

,collect_set(user_id)

--

from table

--

group by date, feature

)

)

--

select date

,distinct_array(flatten(user_id))

,feature

--

from aux

问题是,现在我只需要保留过去90天以上的用户

select date

,collect_set(case when user_created_at < date - interval 90 day

then user_id end) over(

partition by feature

order by cast(timestamp(date) as float)

range between (-90*60*60*24) following and 0 preceding

) as teste

,feature

from table

它不起作用的原因是collect_select()中的过滤器只过滤一天内的用户,而不是过滤过去90天内的所有用户,

我怎样才能正确地得到它?

作为参考,我使用此查询来验证是否正确:

select

count(distinct user_id) as total

,count(distinct case when user_created_at < date('2020-04-30') - interval 90 day then user_id end)

,count(distinct case when user_created_at >= date('2020-04-30') - interval 90 day then user_id end)

--

from table

--

where 1=1

and date >= date('2020-04-30') - interval 90 day

and date <= '2020-04-30'

and feature = 'a_feature'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值