日期:2014-05-19  浏览次数:20486 次

问题已经解决
create   table   t(id   int   ,   [name]   nvarchar(10))

insert   t  
select   1,N '李啊王 '   union   all
select   2,N '王义 '   union   all
select   3,N '张三 '   union   all
select   1,N '李啊王 '   union   all
select   2,N '王张 '   union   all
select   3,N '李王 '   union   all
select   1,N '李王 '   union   all
select   2,N '王李王 '   union   all
select   3,N '张三 '

除了姓之   其他的字出现的次数   按高到低排列


------解决方案--------------------
李啊王,后面这个王算不算?
------解决方案--------------------
晕 lz问题解决了还问~~~~
------解决方案--------------------
select aa,tt=sum(bb) from (
select aa=right([name],len([name])-1) ,bb=count(1)
from t where len([name])=2
group by right([name],len([name])-1)
union all
select aa=right([name],len([name])-2),bb=count(1)
from t where len([name])=3
group by right([name],len([name])-2)
) g
group by aa
order by sum(bb) desc