我有以下 Oracle SQL 查询。给定一个给定的名字和姓氏,它会以任一顺序查找具有一个名字和另一个名字首字母的所有记录。我创建了score
列以将可能的匹配项放在结果集的顶部。
SELECT
surname,
givenname,
(CASE WHEN surname = 'Smith' THEN 2 ELSE 0)
+ (CASE WHEN givenname = 'John' THEN 1 ELSE 0)
AS score
FROM person
WHERE (surname = 'Smith' AND givenname LIKE 'J%')
OR (surname LIKE 'S%' AND givenname = 'John')
OR (surname = 'John' AND givenname LIKE 'S%')
OR (surname LIKE 'J%' AND givenname = 'Smith')
ORDER BY
score DESC,
surname ASC,
givenname ASC;
问题是score
在+
. IDE 报告:
语法错误,预期:
/
*
|
和执行报告:
SQL 错误:ORA-00905:缺少关键字
我究竟做错了什么?有没有更好的方法来计算分数?