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不仅可以对原始的表数据进行排序,也可以对重命名字段数据进行排序。
测试可用。
本文转自TBHacker博客园博客,原文链接:http://www.cnblogs.com/jiqing9006/p/5355229.html,如需转载请自行联系原作者