例如:
编号   城市   ...
  1    深圳
  2    北京
  3    上海
  4    纽约
  5    深圳
  6   上海
...   ...
前3位的 是 深圳 上海 纽约如果获取? 谢谢

解决方案 »

  1.   


    --这样?
    select * from
    (select 城市,cnt=count(1) from 表名 group by 城市)a 
    order by cnt desc
      

  2.   

    select TOP 3 城市
     from (select 城市,count(1) num from 表名 group by 城市) a 
    order by num desc
      

  3.   


    select top 3 dname
     from 
    (select 1 did ,'上海' dname
    union all
    select 2 ,'北京'
    union all
    select 3,'上海'
    union all
    select 4, '北京'
    union all
    select 5,'上海'
    union all
    select 6 ,'北京'
    union all
    select 7,'南京'
    union all
    select 8 ,'北京'
    union all
    select 7,'南京'
    union all
    select 8 ,'郑州') agroup by dname 
    order by count(dname) desc
      

  4.   

    按一楼的。再加一个TOP选择前三就好了。
      

  5.   

    select * from
    (select top 3 address,cnt=count(1) from pageVisits group by address)a 
    order by cnt desc
    是这样 谢谢了 结贴