已知:
表明:Test
字段:BusinessScope
类型:nvarchar
大小:100
+++++++++++++++++++++++++++++++++++++++++++++++
现在表Test中有500万条记录,我现在想从字段BusinessScope提取出次数出现最多的100个关键字出来,请问各位高手有没有好的方法,谢谢!

解决方案 »

  1.   


    create table #t(BusinessScope nvarchar(100))
    go
    insert into #t(BusinessScope) values('a')
    insert into #t(BusinessScope) values('b')
    insert into #t(BusinessScope) values('c')
    insert into #t(BusinessScope) values('a')
    insert into #t(BusinessScope) values('b')
    insert into #t(BusinessScope) values('c')
    insert into #t(BusinessScope) values('b')
    select top 100 BusinessScope,count(*) 次数
    from #t with (nolock)
    group by BusinessScope
    order by count(*) desc,BusinessScope
    drop table #t
    go
      

  2.   

    select top 1000
        BusinessScope
    from test
    group by BusinessScope
    order by count(*) desc
      

  3.   

    select top 100
        BusinessScope
    from test
    group by BusinessScope
    order by count(*) desc
      

  4.   

    select top 100 BusinessScope from Test group by BusinessScope order by Count(BusinesssScope)
      

  5.   

    select top 1000
        BusinessScope
    from test
    group by BusinessScope
    order by Count(BusinesssScope)
      

  6.   

    select top 100 BusinessScope from test group by BusinessScope order by 
    count(BusinesssScope) desc要先进行分组再进行统计按倒序进行排序才能取出最大的来
      

  7.   

    select top 100
        left(BusinessScope,2)
    from BeiJing
    group by   left(BusinessScope,2)
    order by count(*) desc这样就可以呵呵
      

  8.   

    select top 100 left(BusinessScope,2),count(*) 次数
    from BeiJing with (nolock)
    group by left(BusinessScope,2)
    order by count(*) desc,left(BusinessScope,2)
    也可以呵呵
      

  9.   

    select top 100 BusinessScope from test group by BusinessScope order by count(*) desc