select order_time, max(sum_price) from (SELECT order, sum(price) as sum_price FROM orders group by order_time) as table_tmp;