我正在从表格中选择数据,其中3列中的一列与给定的搜索字符串匹配:
SELECT *
FROM CARS
WHERE MODEL LIKE searchString
OR MANUFACTURER LIKE searchString
OR DESCRIPTION LIKE searchString
但我需要根据列的权重,根据匹配的位置来排序结果。即如果在MODEL列中找到匹配项,那么结果在结果中应该比在MANUFACTURER列中找到匹配项时更高。加权为1-MODEL 2-MANUFACTURER 3-DESCRIPTION。
所有的帮助非常感谢,谢谢!
答案 0 :(得分:4)
Oracle的全文搜索(FTS)功能 - Oracle Text--会更快,并根据它的算法提供排名分数...
SELECT c.*,
CASE
WHEN c.model LIKE searchstring THEN 1
WHEN c.manufacturer LIKE searchstring THEN 2
WHEN c.description LIKE searchstring THEN 3
END AS match_rank
FROM CARS c
WHERE c.model LIKE searchstring
OR c.manufacturer LIKE searchstring
OR c.description LIKE searchstring
ORDER BY match_rank
但如果还有两个列匹配,你就不会提及如何处理排名......