我想知道是否有人可以提供帮助。
我回来了错误:
错误代码:1054。'on clause'中的未知列'sub_claims_volume.Claims_Volume'
当我尝试运行下面的查询时。
我认为它与pi_loadings_claims_volume表的连接有关。
我已经从子查询中生成了一个表,并且在这种情况下进行连接没有问题,并且返回了正确的结果。
SELECT bdx_pi_policy_accounts.policyid,
bdx_pi_policy_accounts.renewal,
sub_claims_volume.claims_volume,
pi_loadings_claims_volume.loading
FROM bdx_pi_policy_accounts
LEFT JOIN pi_loadings_claims_volume
ON sub_claims_volume.claims_volume =
pi_loadings_claims_volume.claims_per_year
LEFT JOIN (SELECT pi_claims.policyid,
RIGHT(pi_claims.policykey, 1) AS Renewal,
Count(pi_claims.claimid) AS Claims_Volume
FROM pi_claims
GROUP BY pi_claims.policyid,
pi_claims.policykey) AS sub_claims_volume
ON bdx_pi_policy_accounts.policyid = sub_claims_volume.policyid
AND bdx_pi_policy_accounts.renewal = sub_claims_volume.renewal
答案 0 :(得分:1)
它显示未知列错误的原因是因为join
使用pi_loadings_claims_volume
表执行时,sub_claims_volume
表别名未知(因为i)因此,查询可以'识别Claims_Volume
列。
重新定位join
中的表格(即在sub_claims_volume
条件之前放置join
查询)应该修复它,例如:
SELECT bdx_pi_policy_accounts.policyid,
bdx_pi_policy_accounts.renewal,
sub_claims_volume.claims_volume,
pi_loadings_claims_volume.loading
FROM bdx_pi_policy_accounts
LEFT JOIN (SELECT pi_claims.policyid,
RIGHT(pi_claims.policykey, 1) AS Renewal,
Count(pi_claims.claimid) AS claims_volume
FROM pi_claims
GROUP BY pi_claims.policyid,
pi_claims.policykey) sub_claims_volume
ON bdx_pi_policy_accounts.policyid = sub_claims_volume.policyid
AND bdx_pi_policy_accounts.renewal = sub_claims_volume.renewal
LEFT JOIN pi_loadings_claims_volume
ON sub_claims_volume.claims_volume =
pi_loadings_claims_volume.claims_per_year