【发布时间】:2017-05-02 14:11:30
【问题描述】:
我在匹配来自 2 个不同表的数据时遇到问题。 例子 表 1:a、b、c、d、e(col) 表 2:a,d,e,f,g (col)
如何将table1 col a,d,e中的数据与table2 col a,d,e进行匹配 如果 table1 中的行与 table2 中的行匹配则停止循环?
在我的脚本中,结果总是在匹配数据时重复(当 table1 中的数据匹配时,它仍然循环不与 table2 中的其他数据锁定)。
select distinct x.a, y.a, x.d, y.d, x.e, y.e
from table1 x,
table2 y
where x.a = y.a(+) and x.d = y.d(+) and x.e = y.e(+)
对不起我的英语不好......
编辑:
抱歉,我不能用智能手机很好地打字。 可能是这样的。。
表1
col a--b--c--d--e
1st_row 'Ryan'--'Sofia'--'Bulgaria'--'January'--'107'
2nd_row 'Dony'--'Vienna'--'Austria'--'March'--'103'
3rd_row 'Ryan'--'Berlin'--'Germany'--'January'--'107'
4th_row 'Dony'--'Milan'--'Italy'--'March'--'103'
表2
col a--d--e--f--g
1st_row 'Ryan'--'January'--'107'--'Travel'--'5'
2nd_row 'Ryan'--'January'--'107'--'Bussiness'--'4'
3rd_row 'Dony'--'March'--'103'--'Bussiness'--'9'
4th_row 'Dony'--'March'--'103'--'Bussiness'--'3'
在我的查询中
select distinct x.a, y.a, x.d, y.d, x.e, y.e
from table1 x,
table2 y
where x.a = y.a(+) and x.d = y.d(+) and x.e = y.e(+)
结果是
table1 1st_row matched with table2 1st_row
table1 2nd_row matched with table2 3rd_row
table1 3rd_row matched with table2 1st_row (match duplicated)
table1 4th_row matched with table2 3rd_row (match duplicated)
但我想要的结果是 table1 1st_row 与 table2 1st_row 匹配 table1 2nd_row 与 table2 3rd_row 匹配 table1 3rd_row 与 table2 2nd_row 匹配 table1 4th_row 与 table2 4th_row 匹配
【问题讨论】:
-
添加一些示例表数据和预期结果 - 以及格式化文本。
-
jarlh 请在我的回复帖子中查看我的示例数据和预期结果,谢谢