作者hasio227 (阿进)
看板Database
标题Re: [SQL ] 查询栏位中的字数 查某字出现次数
时间Tue Jun 24 22:44:08 2008
※ 引述《paulyanzi (啧啧)》之铭言:
: 我是使用Access
: 1)
: 不知道是否有SQL 语法可以查询 某一串文字中
: 某一字出现的次数
: EX:This is a book and that is a book.
: 查book出现次数 则会得到 2
: 2)查询某一串文字中的总字数
: EX:This is a book and that is a book.
: 会得到9
create table #test (句子 varchar(100))
insert into #test values('This is a book and that is a book')
insert into #test values('This is a book and that is a book and what is a
book')
insert into #test values('This is a book and that is a book and no book and
good book')
go
select *,len(replace(句子,'book','bookc'))-len(句子)'出现次数'
from #test
go
drop table #test
我是使用MS-SQL写的....XD
因为没用过Access所以不知道有没有replace的函数,或者类似取代字串的函数
如果有的话...可以用小弟我上方的方法去写
我的逻辑如下
将句子里的'book'取代成'bookc',然後查询取代过後的整句句子的字串长度
在减去未取代字串的句子那就可以知道'book'这个单字的出现次数
--
http://hasio.vgocities.net/blog/index.php 我的部落格
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 59.127.194.122
1F:推 paulyanzi:谢谢!! 这样可以成功 也可以应用在中文上 06/26 15:31
2F:推 paulyanzi:虽然造成IO比较大一点 06/26 15:45
※ 编辑: hasio227 来自: 59.127.194.122 (07/22 18:57)