#表1和2结合
with t1 as(select orders.customer_id as customer_id,product_id,customer_name,
rank()over(partition by customer_id order by order_date desc) as rank_product
 from orders
join
customers
on orders.customer_id = customers.customer_id
),
#表3和前两个结合,product_id
t2 as (select t11.product_id,product_name,customer_id,customer_name from products
join 
(
select * from t1
where rank_product = 1
) as t11
on products.product_id = t11.product_id)

select customer_id,customer_name,product_name as latest_order from t2
order by customer_id