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

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

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

with df as(
    SELECT 
    user_id,
    sales_date,
    dense_rank() over(partition by user_id order by sales_date asc) as "RK",
    date_add(sales_date,INTERVAL -row_number() over(partition by user_id order by sales_date asc) day) as "辅助列"
    from sales_tb
)

select
user_id,
count(*) as "days_count"
from df
group by user_id,辅助列
having days_count>=2
order by user_id asc

全部评论

相关推荐

评论
点赞
收藏
分享
牛客网
牛客企业服务