我在表格“OG”中有一个“名称”和“ids”列,想要查找最后一个字母不同且总编辑距离为2的名称。到目前为止,我有:
SELECT
z1.names as names1, z2.names as names2, z1.ids, z2.ids
FROM (SELECT t.names, SUBSTRING(t.names for Length(t.names-1) AS newnames
from "OG" t) z1, (SELECT r.names, SUBSTRING(r.names for Length(r.names-1) AS
newnames1 FROM "OG" r) z2
WHERE levenshtein(z1.newnames, z2.newnames1) = 2 AND z1.id != z2.id
不幸的是,这并不能确保最后的字母不同。有任何修复的想法吗?
答案 0 :(得分:2)
检查最后一个字符:
WHERE levenshtein(z1.newnames, z2.newnames1) = 2 AND z1.id != z2.id
AND substring(z1.names,Length(z1.names)) <> substring(z2.names,Length(z2.names))
请注意,当字符串为空(非空)时,在查询中使用SUBSTRING(t.names for length(t.names)-1)
将失败