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

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

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

select
customer_id
,customer_name
,latest_order
from
(
    select
    o.customer_id customer_id
    ,customer_name
    ,product_name latest_order
    ,rank()over(partition by customer_id order by order_date desc) rk
    from orders o
    join customers c
    on o.customer_id = c.customer_id
    join products p
    on o.product_id = p.product_id
) t
where rk = 1
order by customer_id

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

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