GROUP BY 字段 ORDER BY 字段 DESC

解决方案 »

  1.   

    mysql> select * from test;
    +------+
    | n    |
    +------+
    |    1 |
    |    2 |
    |    1 |
    |    2 |
    |    1 |
    |    1 |
    |    2 |
    |    3 |
    |    2 |
    |    2 |
    |    2 |
    |    2 |
    |    2 |
    |    2 |
    |    2 |
    |    2 |
    +------+mysql> select * from test group by n order by count(*) DESC;
    +------+
    | n    |
    +------+
    |    2 |
    |    1 |
    |    3 |
    +------+
      

  2.   

    create table test (no int)insert into test select 1
    union all select 2
    union all select 3
    union all select 2
    union all select 4
    union all select 2
    union all select 3
    union all select 2
    union all select 5
    union all select 2
    union all select 5
    union all select 2
    union all select 3select  no from test group by no order by count(1) desc
      

  3.   

    mysql>create table test (no int);insert into test select 1
    union all select 2
    union all select 3
    union all select 2
    union all select 4
    union all select 2
    union all select 3
    union all select 2
    union all select 5
    union all select 2
    union all select 5
    union all select 2
    union all select 3;select  no from test group by no order by count(1) desc;