作者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
推 paulyanzi:謝謝!! 這樣可以成功 也可以應用在中文上 06/26 15:31
推 paulyanzi:雖然造成IO比較大一點 06/26 15:45
※ 編輯: hasio227 來自: 59.127.194.122 (07/22 18:57)