在SQL中使用score()来表示多个参数

时间:2015-03-23 22:41:29

标签: sql oracle sql-order-by rank keyword-search

我有3个参数我必须使用以下公式进行评分:

rank = 6*score(name)=3*score(diagnosis)+score(description);

我需要3分吗?

我知道,对于1分,你会写一个这样的查询:

    SELECT score(1), itemName 
FROM item WHERE contains(description, 'database', 1) > 0 
order by score(1) desc; 

如果我要搜索3个字段(名称,描述,诊断?),我将如何在数据库表中查找关键字?

我有这个:

SELECT score(1), patient_name, score(2), diagnosis, score(3),description 
FROM radiology_record r 
WHERE (not sure what to put in the WHERE SECTION)
ORDER BY (6*score(1)+3*score(2)+score(3)) desc; 

1 个答案:

答案 0 :(得分:0)

这是我的解决方案基于我需要的两个表。放射学记录和人员。

    SELECT 6*(score(1)+score(2))+3*score(3)+score(4) as rank
    FROM radiology_record r, persons p 
    WHERE p.person_id = r.patient_id AND contains(first_name, 'dead',   1)>0 
    OR contains(last_name, 'dead', 2)>0 OR contains(diagnosis,'dead', 3) > 0 
    OR contains(description, 'dead', 4) > 0 

    ORDER BY (6*(score(1)+score(2))+3*score(3)+score(4));