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

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

http://www.nowcoder.com/practice/348afda488554ceb922efd2f3effc427

用了四个开窗 但思路应该很清晰


select user_id,first_buy_date,second_buy_date,cnt
from
    (select  user_id,
    first_value(date)over(partition by user_id order by date) as first_buy_date,
    nth_value(date,2)over(partition by user_id order by date) as second_buy_date,
    count(1)over(partition by user_id ) as cnt,
    row_number()over(partition by user_id order by date) as rn
    from order_info
    where  date > '2025-10-15' and product_name in("C++","Java","Python") and status = "completed"
    )t1
where rn = 2
order by user_id
全部评论

相关推荐

头像
09-13 17:44
拐儿中学 Java
点赞 评论 收藏
分享
hso_:哈哈哈哈哈哈我没offer一样在同一道题开喷了
投递深圳同为数码等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务