with t1 as (select c.customer_id,city,total_amount from customers c join orders o on c.customer_id = o.customer_id) select city,sum(total_amount) as total_order_amount from t1 group by city order by sum(total_amount) desc,city asc