本文介绍了基于不匹配值的Oracle SQL INNER Join的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ColA(Table1)     ColB(Table2)
AB3               AB_MNO_3
AB3               AB_PQR_3
AB4               AB_MNO_4
AB4               AB_PQR_4

我想基于两个表中的列使用上面显示的一些非相等值来执行Inner Join.因此,表1可以具有AB3,应该与AB_MNO_3, AB_PQR_3匹配,而AB4应该与AB_MNO_4, AB_PQR_4匹配两个表中这些列中的其余值确实匹配.如果有人提出相同的建议,将不胜感激.

I want to do Inner Join based on columns in two table with some of the non-equal values shown above. So, Table1 can have AB3 which should be matched against AB_MNO_3, AB_PQR_3 while AB4 should be matched against AB_MNO_4, AB_PQR_4Rest of the values in these columns in two tables do match. Would highly appreciate if anyone provides recommendations around the same.

推荐答案

SELECT * FROM Table1 tl INNER JOIN Table2 t2 
ON (tl.ColA = t2.ColB OR (tl.ColA ='AB3' AND t2.ColB='AB_MNO_3')
OR (tl.ColA ='AB3' AND t2.ColB='AB_PQR_3') OR (tl.ColA ='AB4' AND t2.ColB='AB_MNO_4')
OR (tl.ColA ='AB4' AND t2.ColB='AB_PQR_4'))

这篇关于基于不匹配值的Oracle SQL INNER Join的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 18:24