当前位置: 代码迷 >> Sql Server >> 有关问题已经解决
  详细解决方案

有关问题已经解决

热度:85   发布时间:2016-04-27 21:04:55.0
问题已经解决
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
  相关解决方案