Mysql Subquery too slow, query sale number -
i have 3 table: one: table order_info
ordre_id int add_time int
two: table order_goods
id int goods_id int order_id int sale_number int
three: table goods
goods_id int goods_name varchar
now want query goods sale total number , order number, , when goods has no sale number, show zero. utilize subquery, it's slowly, sql like:
select t.* goods tg left bring together ( select sum(og.goods_number) total_num, g.goods_id, g.goods_name order_info oi left bring together order_goods og on oi.order_id=og.order_id left bring together goods g on g.goods_id=og.goods_id oi.add_time>1415635200 ) t on t.goods_id=tg.goods_id order t.total_num desc;
can have goods idea? thanks!
why not remove outer query part , run
select sum(og.goods_number) total_num, g.goods_id, g.goods_name order_info oi left bring together order_goods og on oi.order_id=og.order_id left bring together goods g on g.goods_id=og.goods_id right bring together goods g2 on g2.goods_id=og.goods_id oi.add_time > 1415635200
? indices have set on tables?
mysql subquery
No comments:
Post a Comment