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

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

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


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

全部评论

相关推荐

哞客37422655...:你猜为什么福利这么好还得一直追着你问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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