我想在T-SQL查询中使用DIFFERENCE
关键字来查找两个数据集之间相同或非常相似的数据。 DIFFERENCE
返回1-4的分数,其中4非常相似,1完全不相似。
例如,如果我有两个数据集A和B,它们包含以下内容:
A B
---- ----
adam adam
bob billy
charlie brittany
doug charles
frances diana
heather
kim
我想选择相同或相似的(例如,DIFFERENCE
值为3或4),所以我希望结果集(源于数据集A):
Result
----
adam
charlie
我的想法是将DIFFERENCE
关键字放在WHERE
子句中,如下所示:
SELECT *
FROM A
/* somehow join B here, despite that A and B might not be exact matches such as in charlie and charles */
WHERE DIFFERENCE(A, B) >= 3
我该怎么做?
答案 0 :(得分:1)
select *
from a
join b
on difference(a.name, b.name) = 4;