题解 | 每个顾客购买的最新产品名称
每个顾客购买的最新产品名称
https://www.nowcoder.com/practice/6ff37adae90f490aafa313033a2dcff7
with
t1 as(
select
customer_id,
customer_name,
product_name,
rank()over(partition by customer_id order by order_date desc) as crank
from
orders
left join customers using(customer_id)
left join products using(product_id)
)
,
t2 as(
select
customer_id,
customer_name,
product_name as latest_order
from
t1
where
crank=1
order by
customer_id
)
select * from t2
查看9道真题和解析