我在Oracle DB中有三个表,
01. TBL_ITS_INS_CLAIM_TRANSACTIONS
╔═════════════════════════════╗
║ Id PolicyMasterID Ref_No ║
╠═════════════════════════════╣
║ 01 106 P100 ║
║ 02 106 P200 ║
╚═════════════════════════════╝
02. TBL_ITS_INS_CLAIM_SETTLEMENT
╔══════════════════════════════╗
║ Id CLAIM_TRANSACTIONS_ID ║
╠══════════════════════════════╣
║ 01 01 ║
║ 02 01 ║
║ 03 01 ║
╚══════════════════════════════╝
03. TBL_ITS_INS_CLAIM_SUBROGATION
╔════════════════════════════╗
║ Id CLAIM_TRANSACTIONS_ID ║
╠════════════════════════════╣
║ 01 01 ║
║ 02 01 ║
║ 03 01 ║
╚════════════════════════════
我试过的是,我在下面写了查询获取结果...但它的重复行。 我编辑了代码:
SELECT TBL_ITS_INS_CLAIM_TRANSACTIONS.ID as "Claim Trans ID",
TBL_ITS_INS_CLAIM_SETTLEMENT.ID as "SettlementId",
TBL_ITS_INS_CLAIM_SUBROGATION.ID as "SUBROGATION ID"
FROM TBL_ITS_INS_CLAIM_TRANSACTIONS
LEFT JOIN TBL_ITS_INS_CLAIM_SUBROGATION
ON TBL_ITS_INS_CLAIM_TRANSACTIONS.ID = TBL_ITS_INS_CLAIM_SUBROGATION.CLAIM_TRANSACTIONS_ID
LEFT JOIN TBL_ITS_INS_CLAIM_SETTLEMENT
ON TBL_ITS_INS_CLAIM_TRANSACTIONS.ID = TBL_ITS_INS_CLAIM_SETTLEMENT.CLAIM_TRANSACTIONS_ID
导致上述查询
╔══════════════════════════════════════════════════╗
║ Claim_Trans_ID SettlementId SUBROGATION _ID ║
╠══════════════════════════════════════════════════╣
║ 106 01 01 ║
║ 106 01 02 ║
║ 106 02 01 ║
║ 106 02 02 ║
║ 106 03 01 ║
║ 106 03 02 ║
╚══════════════════════════════════════════════════╝
我希望得到如下结果
╔══════════════════════════════════════════════════╗
║ Claim_Trans_ID SettlementId SUBROGATION _ID ║
╠══════════════════════════════════════════════════╣
║ 106 01 01 ║
║ 106 02 02 ║
║ 106 03 ║
╚══════════════════════════════════════════════════╝
我怎样才能得到如上所述的结果
答案 0 :(得分:1)
只是评论,但太长了。
我感谢您在格式化数据方面的努力,但这对于人们重现您的案例并测试一些代码并不是那么有用。
发布样本数据的最佳方式(恕我直言)发布了一些人们可以轻松运行以创建案例的内容,而无需进行编辑。
在您的问题中,我会将样本数据发布为:
create table TBL_ITS_INS_CLAIM_TRANSACTIONS(Id, PolicyMasterID, Ref_No) as (
select '01', 106, 'P100' from dual union all
select '02', 106, 'P100' from dual
);
create table TBL_ITS_INS_CLAIM_SETTLEMENT(ID, CLAIM_TRANSACTIONS_ID) as (
select '01', '01' from dual union all
select '02', '01' from dual union all
select '03', '01' from dual
);
create table TBL_ITS_INS_CLAIM_SUBROGATION (Id, CLAIM_TRANSACTIONS_ID) as (
select '01', '01' from dual union all
select '02', '01' from dual union all
select '03', '01' from dual
);
创建表后,很容易注意到您的表结构与您的查询不匹配:
SQL> SELECT TBL_ITS_INS_CLAIM_TRANSACTIONS.ID as "Claim Trans ID",
2 TBL_ITS_INS_CLAIM_SETTLEMENT.ID as "SettlementId",
3 TBL_ITS_INS_CLAIM_SUBROGATION.ID as "SUBROGATION ID"
4 FROM TBL_ITS_INS_CLAIM_TRANSACTIONS
5 LEFT JOIN TBL_ITS_INS_CLAIM_SUBROGATION
6 ON TBL_ITS_INS_CLAIM_TRANSACTIONS.ID = TBL_ITS_INS_CLAIM_SUBROGATION.CLAIM_TRAN_SUM_ID
7 LEFT JOIN TBL_ITS_INS_CLAIM_SETTLEMENT
8 ON TBL_ITS_INS_CLAIM_TRANSACTIONS.ID = TBL_ITS_INS_CLAIM_SETTLEMENT.CLAIM_TRAN_SUM_ID;
ON TBL_ITS_INS_CLAIM_TRANSACTIONS.ID = TBL_ITS_INS_CLAIM_SUBROGATION.CLAIM_TRAN_SUM_ID
*
ERROR at line 6:
ORA-00904: "TBL_ITS_INS_CLAIM_SUBROGATION"."CLAIM_TRAN_SUM_ID": invalid
identifier