在WHERE子句中使用DIFFERENCE

时间:2018-02-19 22:20:33

标签: tsql

我想在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

我该怎么做?

1 个答案:

答案 0 :(得分:1)

select * 
from a 
join b
on difference(a.name, b.name) = 4;