0

我有 2 个离散查询,它们都完全按照我的预期返回结果。第一个查询从数据库返回成对的 ID 值。样本对是:[1,2],[3,6],[10,15]

我的第二个查询通过迭代插入行程对,按预期检索数据列表。

9979 和 240 值是用于查询的常量。

关于如何将第一个查询嵌套在第二个查询中的任何建议,以便我一次获得所有结果,按从查询 1 中检索到的 HID 和 SID 分组?(6000 次离散迭代不是一个非常整洁的解决方案)

SELECT     TH1.THR_ID AS HID, SHEAD.THR_ID AS SID
        FROM         RTDEV.TRIP_HEADERS SHEAD INNER JOIN
        RTDEV.TRIP_LINKS TLINK ON SHEAD.TME_ID = TLINK.TME_ID AND SHEAD.THR_ID =
        TLINK.PRIOR_SBSQUNT_THR_ID INNER JOIN
        RTDEV.TRIP_HEADERS TH1 ON TLINK.TME_ID = TH1.TME_ID AND TLINK.THR_ID = TH1.THR_ID
        WHERE     (SHEAD.TME_ID = 9979) AND (TLINK.TME_ID = 9979) AND (TH1.TME_ID = 9979)         AND
        (TLINK.LINK_TYPE = 'S')
        ORDER BY SHEAD.TRIP_NAME

SELECT     ‘1’ AS HID, ‘2’ AS SID, RTDEV.TRIP_HEADERS.TRIP_NAME,
     RTDEV.TRIP_HEADERS.DOP_REF,RTDEV.TRIP_BODIES.DEPARTURE_TIME,RTDEV.TNODED.STRLONGNAME
        FROM         RTDEV.TRIP_BODIES INNER JOIN
        RTDEV.TNODED ON RTDEV.TRIP_BODIES.MASTER_NODE = RTDEV.TNODED.NID INNER JOIN
        RTDEV.TRIP_HEADERS ON RTDEV.TRIP_BODIES.TME_ID = RTDEV.TRIP_HEADERS.TME_ID AND 
        RTDEV.TRIP_BODIES.THR_ID = RTDEV.TRIP_HEADERS.THR_ID
        WHERE (RTDEV.TNODED.NPROJECTGEOGRAPHYID = 240) AND (RTDEV.TRIP_BODIES.TME_ID =
        9979) AND (RTDEV.TNODED.STRLONGNAME IS NOT NULL) 
        AND (RTDEV.TRIP_BODIES.ARRIVAL_TIME <> RTDEV.TRIP_BODIES.DEPARTURE_TIME) AND
        (RTDEV.TRIP_HEADERS.TME_ID = 9979) AND 
        (RTDEV.TRIP_HEADERS.THR_ID IN (1, 2))
        ORDER BY RTDEV.TRIP_BODIES.DEPARTURE_TIME
4

0 回答 0