请问那个写法好,效率高一些?

2016-07-07 15:03 来源:www.chinab4c.com 作者:ecshop专家

  1. select sum(goods_number) from `271utf8`.`ecs_order_goods` AS g ,`271utf8`.`ecs_order_info` AS o WHERE o.order_id=g.order_id and g.goods_id = 3 and o.order_status=1
复制代码


  1. select sum(goods_number) from `271utf8`.`ecs_order_goods` AS g right join `271utf8`.`ecs_order_info` AS o ono.order_id=g.order_id and g.goods_id =3and o.order_status=1
复制代码


我是想查询商品购买次数。

回答:
select sum(goods_number) from `271utf8`.`ecs_order_goods` AS g ,`271utf8`.`ecs_order_info` AS o WHERE g.goods_id = 3 and o.order_status=1 and o.order_id=g.order_id
应该把你的where条件换一个顺序