mysql查询店铺总的订单销量排行

Go_Viola

关注

阅读 93

2023-02-15


根据店铺的订单量,进行销量排行

1.子查询方式

根据店铺的订单量

select sto_store.*,(SELECT count(so_order.order_id)as count FROM so_order where so_order.store_id =sto_store.store_id) as count  FROM sto_store ORDER BY count desc

2.join方式

select sto_store.*,count(so_order.order_id)as count from sto_store join so_order on so_order.store_id = sto_store.store_id GROUP BY so_order.order_id ORDER BY count desc

具测试,在速度方面,子查询的方式比 join 的快一倍


精彩评论(0)

0 0 举报