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

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

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

窗口函数+max 列转行函数

max(case when 列名的条件 then 返回的列 end) as xxx

select
user_id,
max(case when rk=1 then `date` end) as first_buy_date,
max(case when rk=2 then `date` end) as second_buy_date,
cnt
from
(
select 
user_id,
`date`,
dense_rank() over (partition by user_id order by `date`) as rk,
count(`date`) over(partition by user_id) as cnt
from  order_info
where product_name in ('C++','Python','Java')
and `date`>=date('2025-10-15') and status='completed'
)
A
group by user_id,cnt
having cnt>=2
order by user_id

全部评论

相关推荐

08-01 17:57
门头沟学院 Java
点赞 评论 收藏
分享
点赞 评论 收藏
分享
没测评没笔试没感谢信直接无了
投递联发科技等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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