我忽略了一些微不足道的东西。除了尝试练习连接两个查询之外,此查询不是特别的原因。我得到的错误是SQL Server 2008加入两个查询
Msg 156, Level 15, State 1, Line 10
Incorrect syntax near the keyword 'inner'.
Msg 156, Level 15, State 1, Line 16
Incorrect syntax near the keyword 'as'.
并且查询
select t.countyName, x.countyName
from
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient INNER JOIN
tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage > 80)
)
inner join
(
SELECT DISTINCT Patient.patientid, tblStateCounties.countyName, Patient.countyCode
FROM Patient INNER JOIN
tblStateCounties ON Patient.stateCode = tblStateCounties.stateCode AND Patient.countyCode = tblStateCounties.countyCode
WHERE (Patient.patientage < 80)
) as x on t.countyname=x.countyname
你忘了集T别名在你的第一个内部联接 – 2012-07-18 01:43:57