我正在尝试联接多个表(总共11个表),并希望将case\u id列合并为最终联接结果。
帐户可以是主保险、次保险和/或两者。
当我运行下面的查询时,我只从join“k”获得case\ id。如何从join“k”和“l”中查询到case\u id?我用的是claudera hadoop。
例如,我有下面的简化版本:
SELECT DISTINCT a1.id AS Account_Id,
k.Case_Id,
k.Primary_Insurance_Payer_Name,
l.Secondary_Insurance_Payer_Name
FROM account a1 left outer JOIN
(
SELECT k3.Name AS Primary_Insurance_Payer_Name,
k3.Id AS Account_Id,
k4.Id as Case_Id
FROM patient k1
JOIN patient_insurance k2
ON k1.A360_Primary_Insurance__c=k2.Id
JOIN account k3
ON k2.A360_Payer__c=k3.Id
left outer join pep_case k4
on k4.enrolled_patient__c=k1.id
) k ON a1.id=k.Account_Id left outer JOIN
(
SELECT l3.Name AS Secondary_Insurance_Payer_Name,
l3.Id AS Account_Id,
l4.Id as Case_Id
FROM patient l1
JOIN patient_insurance l2
ON l1.A360_Secondary_Insurance__c=l2.Id
JOIN account l3
ON l2.A360_Payer__c=l3.Id
left outer join pep_case l4
on l4.enrolled_patient__c=l1.id) l ON a1.id=l.Account_Id
1条答案
按热度按时间huwehgph1#
执行与处理保险付款人名称类似的操作,在子查询中为其指定不同的别名,然后在最后的select子句中引用这些别名
编辑
一个单独的select查询可以将保险信息连接两次(请参阅别名ppi和spi)。注:我还把join改成了
patient
至pep_case
进入内部连接。