with t as (
select customer_id, product_id
from orders
where (customer_id, order_date) in (
select customer_id, max(order_date)
from orders
group by customer_id
)
)
select t.customer_id, customer_name, product_name as latest_order
from t
join customers cus on t.customer_id=cus.customer_id
join products pro on t.product_id=pro.product_id

京公网安备 11010502036488号