如表table:id   city   other   score
1     a       1      25
1     b       1      25
1     c              25
1     d              25
1     e              25
1     f       1      25
1     g       1      25如何查询"other"不为空的记录,然后按有“other”记录数最多的city排序。

解决方案 »

  1.   

    然后按有“other”记录数最多的city排序:举例说明
      

  2.   

    id  city  other  score 
    1    a      1      25 
    1    a      1      25 
    1    b             25 
    1    d             25 
    1    a             25 
    1    b      1      25 
    1    a      1      25 如何查询"other"不为空的记录,然后按有“other”记录数最多的city排序。
    比如查询出来的是:
    a          3
    b          1
      

  3.   

    select city,count(*) from tt where other is not null
    group by city
    order by count(*)
      

  4.   

    SELECT city,COUNT(*) 
    FROM yourTable 
    WHERE other IS NOT NULL 
    GROUP BY city 
    ORDER BY 2 desc