日期:2014-05-16  浏览次数:20894 次

问个查询后排序的SQL语句
main表 两个字段id、team
能不能按team中某数据出现次数由高到低排序并列出出现的次数

例如

id | team | count
-----------------------
2 |team2 | 10
1 |team1 | 8
3 |team3 | 5

------解决方案--------------------
那如果同一个team中出现不同ip的话,想要什么样结果?
SQL code
SELECT `team`,COUNT(*) AS count 
FROM `main` 
GROUP BY `team`,`ip` 
ORDER BY count DESC

------解决方案--------------------
SQL code
SELECT `team`,COUNT(*) AS count FROM `main` GROUP BY `team` ORDER BY count DESC