题解 | 每个顾客购买的最新产品名称
每个顾客购买的最新产品名称
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
遇到排名问题第一时间用窗口函数