+ -
当前位置:首页 → 问答吧 → 如何进行按匹配度高低进行排序?

如何进行按匹配度高低进行排序?

时间:2011-12-08

来源:互联网

如果要匹配的原文是she is my,怎么让下面的数据按照匹配的多少进行排序?



数据库内容:
she is my sin she is is she
she is is she she she she sin sin
she is my sin she is my
she is my Girl friend she
she is my Son she my


下面这个可以的,但是只能进行一个单词,3个单词该如何写?
SELECT *  
FROM sjk
ORDER BY LENGTH( REPLACE( biaoti, 'she', '' ) ) - LENGTH( biaoti )

作者: asasdisdd   发布时间: 2011-12-08

这个sql无法实现

作者: rucypli   发布时间: 2011-12-08

引用 1 楼 rucypli 的回复:
这个sql无法实现

ORDER BY LENGTH( REPLACE( biaoti, 'she', '' ) ) - LENGTH( biaoti )
这个能帮我讲解下原理不? 我对sql真的不太熟,这里面的REPLACE支持正则不?

作者: asasdisdd   发布时间: 2011-12-08

REPLACE( biaoti, 'she', '' )
把biaoti这个字段里面的she字符替换成空

LENGTH(biaoti)
标题字段的长度

作者: rucypli   发布时间: 2011-12-08

引用 3 楼 rucypli 的回复:
REPLACE( biaoti, 'she', '' )
把biaoti这个字段里面的she字符替换成空

LENGTH(biaoti)
标题字段的长度

原理呢?
如果我执行这句 ORDER BY LENGTH( REPLACE( biaoti, 'she', '' ) ) - LENGTH( biaoti )
结果是这样排的:she 越多的数据越往前排, 我想单个单词可以这样!多个单词为什么不行呢?

mysql 里的 REPLACE支持正则吗?
she is is she she she she sin sin
she is my sin she is is she
she is my Girl friend she
she is my sin she is my
she is my Son she my


作者: asasdisdd   发布时间: 2011-12-08