1

构建了一个子查询,但在 on 子句中获得了一个未知列。

SELECT *
FROM FINAL_Professional_SP_2013_BCARE_AllCOUNTS
INNER JOIN 
(
SELECT COUNT(FINAL_Professional_SP_2013_BCARE_AllCOUNTS.Phy_PLN_CD), SUM(FINAL_MOP_Professional_SP_2013_BCARE.X12_Cost_High), 
Total_Low-SUM(FINAL_MOP_Professional_SP_2013_BCARE.X12_Cost_Low),
Total_High-SUM(FINAL_MOP_Professional_SP_2013_BCARE.X12_Cost_High),  
AVG_WITHIN_Fac-SUM(FINAL_MOP_Professional_SP_2013_BCARE.X12_Cost_Ave) FINAL_MOP_Professional_SP_2013_BCARE 
FROM FINAL_MOP_Professional_SP_2013_BCARE, FINAL_Professional_SP_2013_BCARE_AllCOUNTS
GROUP BY FINAL_Professional_SP_2013_BCARE_AllCOUNTS.TC_Code, FINAL_Professional_SP_2013_BCARE_AllCOUNTS.Phy_PROV_NO
) a ON
FINAL_Professional_SP_2013_BCARE_AllCOUNTS.Phy_PROV_NO=FINAL_MOP_Professional_SP_2013_BCARE.Phy_PROV_NO
AND FINAL_Professional_SP_2013_BCARE_AllCOUNTS.TC_Code=FINAL_MOP_Professional_SP_2013_BCARE.TC_Code;

出现错误 - 错误代码:1054。“on 子句”中的未知列“FINAL_MOP_Professional_SP_2013_BCARE.Phy_PROV_NO”。我已将其更改为 a.Phy_PROV_NO',但得到相同的错误。

4

1 回答 1

2

我怀疑这是你真正想要的:

SELECT allc.TC_Code, allc.Phy_PROV_NO,
       COUNT(allc.Phy_PLN_CD), SUM(bcare.X12_Cost_High), 
       Total_Low-SUM(bcare.X12_Cost_Low),
       Total_High-SUM(bcare.X12_Cost_High),  
       AVG_WITHIN_Fac-SUM(bcare.X12_Cost_Ave) 
FROM FINAL_MOP_Professional_SP_2013_BCARE bcare
JOIN FINAL_Professional_SP_2013_BCARE_AllCOUNTS allc
ON allc.Phy_PROV_NO = bcare.Phy_PROV_NO AND allc.TC_Code = bcare.TC_Code
GROUP BY allc.TC_Code, allc.Phy_PROV_NO

您在子查询之外有子查询的连接条件。

于 2013-05-31T00:56:38.440 回答