题解 | 每个顾客购买的最新产品名称

每个顾客购买的最新产品名称

https://www.nowcoder.com/practice/6ff37adae90f490aafa313033a2dcff7

-- 找到每个顾客最后买的商品id
with max_order as(
select
customer_id,product_id
from orders 
where (customer_id,order_date) in
(select
customer_id,max(order_date) as max_date
from orders 
group by customer_id)
)

select
m.customer_id as customer_id,customer_name,product_name as latest_order
from max_order m
inner join customers c on m.customer_id=c.customer_id
inner join products p on m.product_id=p.product_id
order by customer_id;

全部评论

相关推荐

投递腾讯等公司10个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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