4

ここで些細なことを見落としています。このクエリは、2 つのクエリを結合する練習をしようとする以外に特に理由はありません。私が得るエラーは

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
4

3 に答える 3

6

最初のエイリアスの使用を忘れましたsubquery

于 2012-07-18T01:41:11.947 に答える
3
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)
) rsT
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)
) rsX on rsT.countyname=rsX.countyname
于 2012-07-18T01:41:27.703 に答える
0

使用する

(
    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 t
于 2012-07-18T03:07:12.227 に答える