mysql排序,可以对统计的数据进行排序

sql

SELECT a.*,b.name as address_name,b.tel as address_tel,b.province as address_province,b.city as address_city,b.area as address_area,b.detail as address_detail,c.nickname,c.province,c.city,c.sex,count(d.id) as order_count FROM sh_member a LEFT JOIN sh_member_address b on a.id = b.member_id and b.selected = 1 LEFT JOIN sh_wxuser c on a.wxuser_id = c.id LEFT JOIN sh_order d on a.id = d.member_id GROUP BY a.id ORDER BY order_count

这里面的order_count就是统计出的数据,订单总数。
order不仅可以对原始的表数据进行排序,也可以对重命名字段数据进行排序。

测试可用。

posted @ 2016-04-05 15:21  TBHacker  阅读(3876)  评论(0编辑  收藏  举报