数据表dh_order_detail里一共有169247条数据
原始SQL
SELECTFROM_UNIXTIME(order_time, '%H:%i') 'time',city,district,LEFT (company, 6) company,goods_num,order_price,order_code,order_timeFROMdh_order_detailWHEREprovince_id = 16GROUP BYorder_codeORDER BYorder_time DESCLIMIT 50运行时间4秒多
改进,将GROUP BY外移
SELECT*FROM(SELECTFROM_UNIXTIME(order_time, '%H:%i') 'time',city,district,LEFT (company, 6) company,goods_num,order_price,order_code,order_timeFROMdh_order_detailWHEREprovince_id = 16ORDER BYorder_time DESCLIMIT 50) oGROUP BYorder_code运行时间0.049秒
,心有多大,舞台就有多大。