我写了以下查询:
SELECT R1.RELATIONSHIP_ID, R1.SUPPLIER_ACCOUNT_ID, R2.BUYER_ACCOUNT_ID
FROM RELATIONSHIP R1 JOIN RELATIONSHIP R2
ON (R1.RELATIONSHIP_ID = R2.RELATIONSHIP_ID)
ORDER BY SUPPLIER_ACCOUNT_ID;
对于表格:
1 RELATIONSHIP
.:列:RELATIONSHIP_ID, SUPPLIER_ACCOUNT_ID, BUYER_ACCOUNT_ID
...
2. ACCOUNT
:ACCOUNT_ID, XX_ACCOUNT_ID
....
并给出正确的结果
但是,我想要的更复杂。我需要将第二列和第三列替换called XX_ACOUNT_ID
为要显示两次的列。每一个都有一个独特的SUPPLIER_ACCOUNT_ID
和独一无二的。属于有(从本列引用)和的表。我有点困惑,它需要嵌套自联接还是多个内部联接?或子查询来解决这个问题?BUYER_ACCOUNT_ID
XX_ACCOUNT_ID
ACCOUNT_ID
XX_ACCOUNT_ID
ACCOUNTS
ACCOUNT_ID
SUUPLIER_ACCOUNT_ID & BUYER_ACCONT_ID
XX_ACCOUNT_ID