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

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

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

用临时表做很简单 但是牛客网报错 mysql上结果是对的
create temporary table first_buy
select user_id,min(date)as first_buy_date,count(id)as order_number
from order_info
where user_id in (select user_id
from order_info
where date>'2025-10-15'
and status= 'completed'
and product_name in('C++','Java','Python')
group by user_id
having count(id)>=2)
and date>'2025-10-15'
and status= 'completed'
and product_name in('C++','Java','Python')
group by user_id;

select first_buy.user_id,first_buy.first_buy_date,min(order_info.date)as second_buy_date,first_buy.order_number
from first_buy
join order_info
on first_buy.user_id=order_info.user_id
where first_buy.first_buy_date <order_info.date
group by 1,2,4;
全部评论

相关推荐

点赞 收藏 评论
分享
牛客网
牛客企业服务