【发布时间】:2019-08-29 17:50:40
【问题描述】:
尝试使用 INNER JOIN 构建 SQL。 INNER JOIN 的工作正常,现在我需要添加 MAX() 函数来将行限制为最近的行。在 SELECT cr.PATID、cr.date_of_diagnosis、cr.most_recent_diagnosis 上添加了这个 INNER JOIN client_diagnosis_record ... 收到这个 SQL 代码错误,需要一些帮助,我确信这是一个简单的疏忽,但我的眼睛因为看了这么久而变得模糊......
语法错误:[SQLCODE::
SQLCODE: <-4>:<A term expected, beginning with one of the following: identifier, constant, aggregate, %ALPHAUP, %EXACT, %MVR, %SQLSTRING, %
[%msg: < The SELECT list of the subquery
SELECT pd.patient_name,
cr.PATID,
cr.date_of_diagnosis,
cr.EPISODE_NUMBER,
ce.diagnosing_clinician_value,
ce.data_entry_user_name,
most_recent_diagnosis
FROM client_diagnosis_record cr
INNER JOIN patient_current_demographics pd ON cr.patid = pd.patid
INNER JOIN client_diagnosis_entry ce ON ce.patid = pd.patid
AND cr.ID = ce.DiagnosisRecord
INNER JOIN client_diagnosis_record ON (SELECT cr.PATID,
cr.date_of_diagnosis,
cr.most_recent_diagnosis
FROM ( SELECT patid,
date_of_diagnosis,
MAX(ID) AS most_recent_diagnosis
FROM client_diagnosis_record) cr
INNER JOIN RADplus_users ru ON ru.staff_member_id = ce.diagnosing_clinician_code
WHERE cr.PATID <> '1'
AND ce.diagnosis_status_value ='Active'
AND (ru.user_description LIKE '%SOA' OR ru.user_description LIKE '%OA')
GROUP BY cr.PATID
【问题讨论】:
-
您问题中的代码格式不正确
-
你能帮我确定正确的代码格式吗,指出细节以便我修复它
-
不正确的格式是否属于? INNER JOIN client_diagnosis_record ON (SELECT cr.PATID, cr.date_of_diagnosis, cr.most_recent_diagnosis FROM (SELECT patid, date_of_diagnosis, MAX(ID) AS most_recent_diagnosis)
-
您没有看到代码块末尾的 FROM client_diagnosis_record ) 吗?
-
什么是数据库? Sybase、Oracle、PostgreSQL 等
标签: sql max inner-join winsql