已知:
表明:Test
字段:BusinessScope
类型:nvarchar
大小:100
+++++++++++++++++++++++++++++++++++++++++++++++
现在表Test中有500万条记录,我现在想从字段BusinessScope提取出次数出现最多的100个关键字出来,请问各位高手有没有好的方法,谢谢!
表明:Test
字段:BusinessScope
类型:nvarchar
大小:100
+++++++++++++++++++++++++++++++++++++++++++++++
现在表Test中有500万条记录,我现在想从字段BusinessScope提取出次数出现最多的100个关键字出来,请问各位高手有没有好的方法,谢谢!
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
BusinessScope
from test
group by BusinessScope
order by count(*) desc
BusinessScope
from test
group by BusinessScope
order by count(*) desc
BusinessScope
from test
group by BusinessScope
order by Count(BusinesssScope)
count(BusinesssScope) desc要先进行分组再进行统计按倒序进行排序才能取出最大的来
left(BusinessScope,2)
from BeiJing
group by left(BusinessScope,2)
order by count(*) desc这样就可以呵呵
from BeiJing with (nolock)
group by left(BusinessScope,2)
order by count(*) desc,left(BusinessScope,2)
也可以呵呵