我有一张表 table
     id  countID
     1     2
     2     2
     3     3
     4     1
     5     3
     6     2
     7     3
     8     1
    现在要在这张表中 查询countID 字段 中出相同 记录出现次数的一个排行
     在table中countID中有2 3 1 重复出现 重复次数最多的拍照前面
    我想得到这样的一个查询
      countid
       2 
       3
       1

解决方案 »

  1.   

    SELECT countid
    FROM   TableName
    GROUP BY countid
    ORDER BY COUNT(DISTINCT countid) DESC
      

  2.   


    ---..
    SELECT countid
    FROM   TableName
    GROUP BY countid
    ORDER BY COUNT(countid) DESC
      

  3.   

    select countid from tb group by countid order by conut(*) desc
      

  4.   

    看到简单问题都想抢分,一抢就激动。我也手误select countid from tb group by countid order by count(*) desc
      

  5.   

    LS正解。。count函数统计排序。
      

  6.   


    --测试数据
    create table 表(id int,countID int)
    insert into 表
    select 1,2 union all
    select 2,2 union all
    select 3,3 union all
    select 4,1 union all
    select 5,3 union all
    select 6,2 union all
    select 7,3 union all
    select 8,1
    select countID from 表
    group by countID
    order by  count(countID) desc
      

  7.   

    select countid from tableName group by countid order by count(countid) desc