比较top2 select语句中的值

时间:2016-02-24 04:57:57

标签: sql sql-server

SELECT TOP 2
    ALLOCATIONS_FW.VEHICLE_ID_FW,
    ALLOCATIONS_FW.END_DATE_FW,
    ALLOCATIONS_FW.START_DATE_FW,
    ALLOCATIONS_FW.LOCATION_CODE_FW,
    ALLOCATIONS_FW.COMPANY_CODE_FW
FROM
    ALLOCATIONS_FW
WHERE
    ALLOCATIONS_FW.START_DATE_FW =
            (SELECT MAX(ALLOCATIONS_FW.START_DATE_FW)
             FROM ALLOCATIONS_FW) AND
    VEHICLE_ID_FW =
            (SELECT VEHICLE_ID_FW
            FROM ALLOCATIONS_FW 
            WHERE ALLOCATIONS_FW.RECORD_NUMBER_FW = %RECORD_NUMBER_FW%) AND
    ALLOCATIONS_FW.RECORD_NUMBER_FW = %RECORD_NUMBER_FW%

如何比较top2 select语句中的前1和前2的值?

VEHICLE_ID_FW|END_DATE_FW|START_DATE_FW|LOCATION_CODE_FW |COMPANY_CODE_FW
ABC123       | //        | 02/15/2016  |    103          |      NAC
ABC123       |02/14/2015 | 01/14/2016  |    100          |      VIC

0 个答案:

没有答案