数据表dh_order_detail 里一共有169247条数据
原始SQL
SELECT FROM_UNIXTIME(order_time, '%H:%i') 'time', city, district, LEFT (company, 6) company, goods_num, order_price, order_code, order_time FROM dh_order_detail WHERE province_id = 16 GROUP BY order_code ORDER BY order_time DESC LIMIT 50
运行时间4秒多
改进,将GROUP BY外移
SELECT *FROM ( SELECT FROM_UNIXTIME(order_time, '%H:%i') 'time', city, district, LEFT (company, 6) company, goods_num, order_price, order_code, order_time FROM dh_order_detail WHERE province_id = 16 ORDER BY order_time DESC LIMIT 50 ) oGROUP BY order_code运行时间0.049秒