题解 | #某宝店铺连续2天及以上购物的用户及其对应的天数#

某宝店铺连续2天及以上购物的用户及其对应的天数

https://www.nowcoder.com/practice/63ac3be0e4b44cce8dd2619d2236c3bf

select
    user_id,
    count(1) as days_count
from
(select
    user_id,
    row_number() over (partition by user_id order by sales_date) as flag,
    date_sub(sales_date, interval row_number() over (partition by user_id order by sales_date) day) as date_flag
from
(select
    user_id,
    sales_date
from sales_tb
group by 
    user_id,
    sales_date
) as a 
) as b
group by user_id
having count(1) >= 2

全部评论

相关推荐

牛客410815733号:这是什么电影查看图片
点赞 评论 收藏
分享
无敌虾孝子:喜欢爸爸还是喜欢妈妈
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务