with
a as (
select
*,
dense_rank() over(partition by customer_id order by order_date desc) as drk
from orders o
left join customers c using(customer_id)
left join products p using(product_id)
)
select
a.customer_id,
a.customer_name,
a.product_name as latest_order
from a
where a.drk=1
order by a.customer_id

京公网安备 11010502036488号