题解 | #牛客的课程订单分析(五)#可读性好就是麻烦

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

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

with first as  (
  select user_id,min(date) first_date,count(*) cnt
  from order_info
  where date>='2025-10-15'
  and status='completed'
  and product_name in ('C++','Java','Python')
  group by user_id
  having count(*)>=2
),
second as (
SELECT user_id,date second_date
from (
  select *
  ,row_number()over(partition by user_id order by date) posn
  from order_info
  where date>='2025-10-15'
  and status='completed'
  and product_name in ('C++','Java','Python')
) as t
where posn=2
)
SELECT  first.user_id,first.first_date,second.second_date,first.cnt
from first 
inner join second
on first.user_id=second.user_id
order by first.user_id
全部评论

相关推荐

昨天 09:59
复旦大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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