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

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

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

with t1 as
(select distinct sales_date, user_id,
SUBDATE(sales_date, INTERVAL dense_rank() over(partition by user_id order by sales_date) DAY) as tmp_date
from sales_tb),
t2 as
(select user_id,
count(tmp_date) as tmp_days_count
from t1
group by user_id, tmp_date)
select user_id,
max(tmp_days_count) as days_count
from t2 
where tmp_days_count>=2
group by user_id
order by user_id asc

全部评论

相关推荐

2025-12-17 17:15
华东师范大学 运营
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务