首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

相关度排序有关问题

2012-01-22 
相关度排序问题如何利用SQL语法来实现数据库搜索的相关度排序例如:字段1字段2字段3字段4....12005年高层封

相关度排序问题
如何利用SQL语法来实现数据库搜索的相关度排序
例如:
          字段1         字段2       字段3         字段4....
1         2005年       高层       封闭小区     精装修
2         2005年       高层       半封闭式     精装修

当用户搜索条件为:字段1   like   2005年,字段2   like   高层,字段3   like   半封闭,字段4   like   毛坯   的时候,第二条数据能够因为匹配的字段更多   而排在前面。换句话说就是能够在数据库中找到与给定记录更加匹配的记录,并按照匹配的程度进行排序。各位有没有什么办法或写法啊。!

[解决办法]
--后面加上order,如:
Order by (Case when Charindex( '2005年 ',字段1)> 0 then 1 else 0 end)+
(Case when Charindex( '高层 ',字段2)> 0 then 1 else 0 end)+
(Case when Charindex( '半封闭 ',字段3)> 0 then 1 else 0 end)+
(Case when Charindex( '毛坯 ',字段4)> 0 then 1 else 0 end) Desc

热点排行