从命名查询中选择

时间:2013-08-28 15:50:20

标签: sql ms-access ms-access-2013

我在MS Access 2013中遇到以下查询问题:

SELECT *
FROM (((
      (SELECT Stop.TAGeoID AS TAGeoID,
              Trip.TripNo AS TripNo
       FROM ((((Trip
                INNER JOIN BTStopTimes ON Trip.TripNo = BTStopTimes.TripNumber)
               INNER JOIN TripsTxt ON (Trip.TripNo = TripsTxt.trip_id
                                       AND Left(TripsTxt.shape_id, 3) <> 'ELD'))
              INNER JOIN PatternDetail ON Trip.PatternID = PatternDetail.PatternID
              AND BTStopTimes.Sequence = PatternDetail.StopSortOrder)
             INNER JOIN Stop ON Stop.GeoID = PatternDetail.GeoID)) AS t3
    LEFT JOIN
      (SELECT F10,
              F16
       FROM PatternStopsRaw
       WHERE F16 <> ''
       GROUP BY F10,
                F16)R ON R.F10 = t3.TAGeoID)
   LEFT JOIN Timepoint ON Timepoint.PlaceID = R.F16)
  LEFT JOIN
    (SELECT *
     FROM t3
     INNER JOIN TripDetail ON t3.TripNo = TripDetail.TripNo)TripTripDetail ON (Timepoint.TimePointID = TripTripDetail.TimepointID))

它说有语法错误

The Microsoft Access database engine cannot find the input table or query t3. Make sure it exists and that its name is spelled correctly

似乎Access不允许在同一查询中从命名查询中进行选择。

有什么建议吗?

PS:*仅用于测试目的,我会在查询后删除它们。

1 个答案:

答案 0 :(得分:1)

是的,似乎Access无法识别该级别的[t3]别名。也许您可以尝试创建查询...

SELECT Stop.TAGeoID AS TAGeoID,
              Trip.TripNo AS TripNo
       FROM ((((Trip
                INNER JOIN BTStopTimes ON Trip.TripNo = BTStopTimes.TripNumber)
               INNER JOIN TripsTxt ON (Trip.TripNo = TripsTxt.trip_id
                                       AND Left(TripsTxt.shape_id, 3) <> 'ELD'))
              INNER JOIN PatternDetail ON Trip.PatternID = PatternDetail.PatternID
              AND BTStopTimes.Sequence = PatternDetail.StopSortOrder)
             INNER JOIN Stop ON Stop.GeoID = PatternDetail.GeoID)

...作为Access中保存的查询,将其命名为[t3],然后在主查询中引用它。