日期:2014-05-19  浏览次数:20735 次

问题,如何按照某一列的值得多少进行排序?
select   a   from   table...
得到
aaa
bbb
bbb
ccc
ccc
bbb
aaa
bbb
ccc
========
4个bbb,3个ccc,2个aaa.

我希望结果是
bbb
bbb
bbb
bbb
ccc
ccc
ccc
aaa
aaa

就是这一列值最多的数据放在开头......
求教..

------解决方案--------------------
select * from tablename x
order by (select count(*) from tablename where a=x.a) desc
------解决方案--------------------
select * from tablename x
order by (select count(1) from tablename where a=x.a) desc

------解决方案--------------------
這樣就可以了


select a from t group by a order by count(*) desc