表内容例如:
a列     b列
123     x
121     y
145     x
176     z
148     y
......用一个sql语句得到b列字符分别在表中的个数并降序排列得前十

解决方案 »

  1.   

    select b,count(*) from tt order by count(*) desc limit 10
      

  2.   

    谢谢楼上,但是报错
    ERROR 1111: Invalid use of group function怎么回事?
      

  3.   

    select b,count(*) from tt group by b order by count(*) desc limit 10
      

  4.   

    还是报ERROR 1111: Invalid use of group function 
      

  5.   

    用MYSQL,什么版本?
    select b,count(*) from tt group by b 是否能运行
      

  6.   

    select kav,count(*) from sample_info group by kav
    可以正常执行
      

  7.   

    select b,count(*) from tt group by b能正常执行
      

  8.   

    mysql  Ver 11.18 Distrib 3.23.54, for redhat-linux-gnu (i386)
    版本
      

  9.   

    select b,count(*) as rr from tt group by b order by rr
    是否能运行
      

  10.   

    select b,count(*) as rr from tt group by b order by b能运行
    order by后面跟count(*)就不能运行
      

  11.   

    版本太低,
    CREATE TABLE TT AS
    select b,count(*) as rr from tt group by b 
    SELECT * FROM NEWTT ORDER BY RR DESC LIMIT 10
      

  12.   

    select b,count(*) as rr from tt group by b order by b
    能运行么?
    能降序排列并显示?
    好,我也试一试
    谢谢
      

  13.   

    你这个好像不符合要求吧
    你这个的运行结果是按照b列分组并把b列排序
    但是他的问题好像是按照b列分组并把同一b组的a列内容排序
    应该怎么写呢?请指教
      

  14.   

    select b,count(*) as rr from tt group by b order by RR