题解 | #牛客的课程订单分析(四)#

牛客的课程订单分析(四)

https://www.nowcoder.com/practice/c93d2079282f4943a3771ca6fd081c23

select t.user_id, t.date as first_buy_date ,t.cnt from
(select *,row_number() over (partition by user_id order by date ) as rk,count(product_name) over (partition by user_id ) as cnt
from order_info 
 where date > '2025-10-15'
   and status ='completed'
   and product_name in ('C++','Python','Java')) as t

where t.rk=1 and t.cnt>=2
order by user_id

2种做法

法一:简单

基于订单分析二做聚合

法二:窗口函数--2个注意点

row_number() over (partition by user_id order by date ) as rk---rk=1 是初次购买日期 first_buy_date

count(product_name) over (partition by user_id ) as cnt--cnt>=2 【对用户分组再计算该用户购买课程数count(product_name)】

全部评论

相关推荐

点赞 评论 收藏
分享
06-08 22:25
门头沟学院 Java
从零开始的转码生活:这hr不会打开手机不分青红皂白给所有人群发这句话,过一会再给所有人再发一遍,这肯定会有重复的,不管,再过一会再发一遍
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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