select
od.order_id,
c.customer_name,
max_order_date as order_date
from (
select
customer_id,
max(order_date) as max_order_date
from
orders
group by
customer_id
)a
inner join
orders as od
on
a.customer_id = od.customer_id
and
a.max_order_date = od.order_date
inner join
customers as c
on
c.customer_id = a.customer_id
order by
customer_name


京公网安备 11010502036488号