create table w
(
word nvarchar(100)
)
insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select('<:')
select* from w
declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地<.'
我想从这句话中找出w表在的关键字并显示出来,包括显示几次。
结果如下:
去 2
第三方 1
, 1
大学看看该如何实现。。
------解决方案--------------------
- SQL code
create table w(word nvarchar(100))insert into w(word)select('去')union allselect('第三方')union allselect(',')union allselect('士大夫')union allselect('girls')union allselect(' <:')declare @t nvarchar(1000)set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.'select WORD,LEN(@T)-LEN(REPLACE(@T,WORD,'')) from w WHERE LEN(@T)-LEN(REPLACE(@T,WORD,'')) >0DROP TABLE W/*去 2第三方 3, 1*/
------解决方案--------------------
- SQL code
--是次数啊,SORRY,这次应该对了create table w(word nvarchar(100))insert into w(word)select('去')union allselect('第三方')union allselect(',')union allselect('士大夫')union allselect('girls')union allselect(' <:')declare @t nvarchar(1000)set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.'select WORD,(LEN(@T)-LEN(REPLACE(@T,WORD,''))) /LEN(WORD)from w WHERE LEN(@T)-LEN(REPLACE(@T,WORD,'')) >0DROP TABLE W/*去 2第三方 1, 1*/
------解决方案--------------------
- SQL code
create table w ( word nvarchar(100) ) insert into w(word) select('去') union all select('第三方') union all select(',') union all select('士大夫') union all select('girls') union all select(' <:') declare @t nvarchar(1000) set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.' select word,(len(@t)-len(replace(@t,word,'')))/len(word)from wwhere @t like '%'+word+'%'--结果word ---------------------------------------------------------------- -----------去 2第三方 1, 1(3 行受影响)
------解决方案--------------------
- SQL code
create table w ( word nvarchar(100) ) insert into w(word) select('去') union all select('第三方') union all select(',') union all select('士大夫') union all select('girls') union all select(' <:') declare @t nvarchar(1000) set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.' select *,(len(@t)-len(replace(@t,word,'')))/len(word)from w where @T like '%'+word+'%'
------解决方案--------------------
create table w
(
word nvarchar(100)
)
insert into w(word)
select('去')
union all
select('第三方')
union all
select(',')
union all
select('士大夫')
union all
select('girls')
union all
select(' <:')
declare @t nvarchar(1000)
set @t='我们今天要去的地方要和第三方枯叶,顶替顶替去要夺枯地枯需要地 <.'
select word,(len(@t)-len(replace(@t,word,'')))/len(word)
from w
where @t like '%'+word+'%'
------解决方案--------------------
我顶,看看有灭有分^_^
------解决方案--------------------