[英]Oracle SQL column comparison
I have two columns and I would like to make a comparison to find out if they are equal, the problem is when same keyword is written in different way.我有两列,我想比较一下它们是否相等,问题是当相同的关键字以不同的方式编写时。
For example if column_1 = 123 Maryland Ave and column_2 = 123 Maryland Avenue these two column should be equal and I would like to create a third column in the query to show if they are equal or not, thank you for your help!例如,如果 column_1 = 123 Maryland Ave 和 column_2 = 123 Maryland Avenue 这两列应该相等,我想在查询中创建第三列以显示它们是否相等,谢谢您的帮助!
Column_1 Column_2 Equal?
-----------------------------------------------------------
123 Maryland Ave 123 Maryland Avenue Yes
456 Maryland Ave 123 Maryland Ave No
One option is to check similarity between those values:一种选择是检查这些值之间的相似性:
SQL> with test (id, col1, col2) as
2 (select 1, '123 Maryland Ave', '123 Maryland Avenue' from dual union all
3 select 2, '456 Maryland Ave', '123 Maryland Ave' from dual
4 )
5 select id, col1, col2,
6 utl_match.jaro_winkler_similarity(col1, col2) as sim
7 from test;
ID COL1 COL2 SIM
---------- ---------------- ------------------- ----------
1 123 Maryland Ave 123 Maryland Avenue 96
2 456 Maryland Ave 123 Maryland Ave 87
SQL>
Now, you have to decide the threshold which satisfies your needs.现在,您必须确定满足您需求的阈值。 Is it 90%?
是90%吗? Let's suppose it is.
让我们假设它是。 Then you'd use
CASE
expression:然后你会使用
CASE
表达式:
SQL> with test (id, col1, col2) as
2 (select 1, '123 Maryland Ave', '123 Maryland Avenue' from dual union all
3 select 2, '456 Maryland Ave', '123 Maryland Ave' from dual
4 )
5 select id, col1, col2,
6 case when utl_match.jaro_winkler_similarity(col1, col2) > 90 then 'Yes'
7 else 'No'
8 end as equal
9 from test;
ID COL1 COL2 EQUAL
---------- ---------------- ------------------- -------
1 123 Maryland Ave 123 Maryland Avenue Yes
2 456 Maryland Ave 123 Maryland Ave No
SQL>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.