我不确定我的sql代码有什么问题。它告诉我最后有一个错误但是说它在''。谢谢你的帮助!
SELECT PatientID, HCPCCode, HCPCCodeCount, DischargeStatus, State, Gender, Race, Age, County, ProcedureDate, ClaimThroughDate, ICDAccessCode, ClaimID,
CASE WHEN DiagnosisCodeType = 4 THEN 4 END code4,
CASE WHEN DiagnosisCodeType = 4 THEN `Procedures` END procedures4,
CASE WHEN DiagnosisCodeType = 4 THEN `ICD9Codes` END ICD94,
CASE WHEN DiagnosisCodeType = 6 THEN 6 END code6,
CASE WHEN DiagnosisCodeType = 6 THEN `Procedures` END procedures6,
CASE WHEN DiagnosisCodeType = 7 THEN 7 END code7,
CASE WHEN DiagnosisCodeType = 7 THEN `Procedures` END procedures7,
CASE WHEN DiagnosisCodeType = 8 THEN 8 END code8,
CASE WHEN DiagnosisCodeType = 8 THEN `Procedures` END procedures8,
CASE WHEN DiagnosisCodeType = 9 THEN 9 END code9,
CASE WHEN DiagnosisCodeType = 9 THEN `Procedures` END procedures9
FROM ((SELECT subquery2.*, GROUP_CONCAT(CONCAT (ICDAccessCode) SEPARATOR ', ') AS ICD9Codes
FROM (SELECT subquery.*, GROUP_CONCAT(CONCAT (ProcedureID) SEPARATOR ', ') AS Procedures
FROM(SELECT revenue.HCPCCode, revenue.HCPCCodeCount, patient.*, icd9.DiagnosisCodeType, procedures.ProcedureID, procedures.ProcedureDate, claims.ClaimThroughDate, icd9.ICDAccessCode
FROM `cmsdata-outpatient-2012`.revenue revenue
RIGHT OUTER JOIN `cmsdata-outpatient-2012`.patient patient
ON revenue.ClaimID = patient.ClaimID
JOIN `cmsdata-outpatient-2012`.diagnosisicd9 icd9
ON revenue.ClaimID = icd9.ClaimID
JOIN `cmsdata-outpatient-2012`.claims claims
ON revenue.ClaimID = claims.ClaimID
JOIN `cmsdata-outpatient-2012`.procedures procedures
ON revenue.ClaimID = procedures.ClaimID
AND revenue.HCPCCode IN (659, 698, 5116, 5118, 5122, 5123, 5127, 12164, 12171, 16976, 17283)
GROUP BY ClaimID, DiagnosisCodeType) AS subquery
) subquery2)) GROUP BY ClaimID AS subquery3;