日期:2014-05-17 浏览次数:20443 次
create table table1(class int, pass varchar(100))
insert into table1
select 1 ,'张三;李四;王麻子' union all
select 2 ,'黎明;刘德华;张学友' union all
select 3 ,'张三;张学友'
go
select top 5 v as pass
from
(
select class,
SUBSTRING(t.pass, number ,CHARINDEX(';',t.pass+';',number)-number) v
from table1 t,master..spt_values s
where s.number >=1
and s.type = 'P'
and SUBSTRING(';'+t.pass,s.number,1) = ';'
)t
group by v
order by COUNT(*) desc
/*
pass
张学友
张三
王麻子
刘德华
李四
*/