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不僅可以對原始的表數據進行排序,也可以對重命名字段數據進行排序。

測試可用。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM