[SQL ] MySQL中紀錄的重複次數從最多到最少的排名

作者: red0whale (red whale)   2016-08-22 10:42:12
資料庫名稱: MySQL
資料庫版本: (略)
內容/問題描述:
假設資料表`table`中有欄位`country`
其中一部份`country`的紀錄包含:`United States`、`Japan`、`China`、`Germany`和`Taiwan`
我想要將這5個`country`的紀錄以「紀錄的重複次數多寡」來做排序
請問我該怎麼做?
作者: johnney (Johnney)   2016-08-22 12:02:00
where country like ?
作者: streetbad (翊)   2016-08-22 13:45:00
where country in ('a','b','c','d','e')
作者: JeremyJoung (J.J.)   2016-08-23 16:02:00
把這個排序後的結果 和其他TABLE作JOIN後再ORDER一次
作者: streetbad (翊)   2016-08-23 16:54:00
建個暫存資料表把第一次查詢的排序塞進去並給ID與想要查詢的其他資料表JOIN後 再依需求ORDER BY另外ORDER BY 應該可以 ORDER BY A DESC,B ASC之類的方式來進行不同欄位的排序動作
作者: shadowjohn (轉角遇到愛)   2016-09-13 14:45:00
count(b.*) from .left outer join b.xx on a.id=b.idorder by counts desc

Links booklink

Contact Us: admin [ a t ] ucptt.com