select customer_id,customer_name,latest_order
from (
select o.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
) z
where z.rk = 1

京公网安备 11010502036488号