我知道这个问题可能经常被问到,但是我一直在尝试通过左联接找到问题。我四处搜寻并尝试了一些不同的方法,但是仍然无法确定问题所在。
left join (
SELECT
MAX(e.date) as MaxDate
,e.patientID
FROM
labdata ld
inner join enc e on e.encounterID = ld.EncounterId
and e.deleteFlag = 0
and ld.deleteFlag = 0
and ld.futureflag = 0
and ld.cancelled = 0
and ld.received = 1
inner join @patients t on t.patientID = e.patientID
inner join structsocialhistory SSH on SSH.encounterId = e.encounterID
INNER JOIN (structdatadetail SDD ON SSH.catid = SDD.catid
AND SSH.itemid = SDD.itemid
AND SSH.detailid = SDD.id)
WHERE SSH.catid = 10619
AND SSH.itemid = 318681
AND SSH.detailID = 49 AND SSH.ValueID =82
OR SSH.detailID = 51 AND SSH.ValueID IN(88,89,145)
AND SSH.detailID IN(52,53,98,99,100,101,106,107,108,109) AND CONVERT(VARCHAR(MAX), SSH.Value) = 'Yes'
GROUP BY
e.patientID
) SmokeCounselMaxDate on SmokeCounselMaxDate.patientid = u.uid
答案 0 :(得分:2)
从此位删除括号:
INNER JOIN (structdatadetail SDD ON SSH.catid = SDD.catid
AND SSH.itemid = SDD.itemid
AND SSH.detailid = SDD.id)
答案 1 :(得分:-1)
检查一下,我删除了表structdatadetail的括号
左联接(
选择
MAX(e.date)作为MaxDate
,e.patientID
从
实验室数据
内部连接enc e on e.encounterID = ld.EncounterId
和e.deleteFlag = 0
和ld.deleteFlag = 0
和ld.futureflag = 0
并且ld.cancelled = 0
并且ld.received = 1
内部联接@患者t上的t.patientID = e。PatientID
SSH上的内部连接structsocialhistory SSH.encounterId = e.encounterID
内连接structdatadetail SDD ON SSH.catid = SDD.catid
AND SSH.itemid = SDD.itemid
AND SSH.detailid = SDD.id
SSH.catid = 10619
AND SSH.itemid = 318681
AND SSH.detailID = 49 AND SSH.ValueID = 82
或SSH.detailID = 51 AND SSH.ValueID IN(88,89,145)
AND SSH.detailID IN(52,53,98,99,100,101,106,107,108,109)AND CONVERT(VARCHAR(MAX),SSH.Value)='是'
GROUP BY
e.patientID
)SmokeCounselMaxDate.patientid = u.uid上的SmokeCounselMaxDate