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

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

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

with temp as 
(
    select 
    customer_id,
    product_id,
    row_number() over(partition by customer_id order by order_date desc) as rnk
    from orders
)

select 
tp.customer_id,
c.customer_name,
p.product_name as latest_order
from temp tp
inner join customers c 
on c.customer_id = tp.customer_id
inner join products p 
on p.product_id = tp.product_id
where tp.rnk = 1
order by 
tp.customer_id asc

遇到排名问题第一时间用窗口函数

全部评论

相关推荐

不愿透露姓名的神秘牛友
03-20 12:46
瘦嘟嘟右卫门:百度文库网盘的暑期也没约面吗
点赞 评论 收藏
分享
03-27 01:58
已编辑
西北工业大学 Java
在平静中度过当下:如果这个bg也简历挂的话可能他们现在不缺人了吧,我也是这两天投的,阿里和快手投的岗都是简历秒挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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