开发者

what is the mysql query to perform frequency ranking

开发者 https://www.devze.com 2022-12-23 16:46 出处:网络
am looking for a query whic开发者_如何学编程h will perform frequency ranking, so that the record which has maximum occurances of supplied \"key word\" will be listed top in the result.

am looking for a query whic开发者_如何学编程h will perform frequency ranking, so that the record which has maximum occurances of supplied "key word" will be listed top in the result.

my fields in the table are text and id. Can any one help me in this. Thanks in advance.


How about this: replace the keyword with nothing, then compare the new size to the old size. The difference, divided by the length of the keyword, is equal to the number of times it was found.

select id, text, 
    (length(text)-length(replace(text, 'KEYWORD', '')))/length('KEYWORD') 
from TableName 
where text like '%KEYWORD%';

This seems kind of flaky to me, but since you are trying to do it with SQL I could not think of a SQL string comparison function that returns the number of times a string was found.

0

精彩评论

暂无评论...
验证码 换一张
取 消