带lead函数的sql server查询需要时间

dw1jzc5e  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(242)

我试图执行下面的代码,这是太多的时间来执行。

SELECT  
    ROW_NUMBER() OVER (PARTITION BY a.DeviceID, a.SubscriberLoginID ORDER BY a.GPSCommandID) Row,
    a.DeviceId,
    SubscriberLoginID,
    CabLatitude, CabLongitude,
    LEAD(CabLatitude) OVER (PARTITION BY a.DeviceId, SubscriberLoginID ORDER BY CONVERT(DATETIME, GPSDateTime)) NextLat,
    LEAD(CabLongitude) OVER (PARTITION BY a.DeviceId, SubscriberLoginID ORDER BY CONVERT(DATETIME, GPSDateTime)) NextLong,
    MeterStatusId,
    LEAD(MeterStatusId) OVER (PARITITON BY a.DeviceId, SubscriberLoginID ORDER BY CONVERT(DATETIME,GPSDateTime)) NextStatus,
    a.GPSDateTime,
    LEAD(GPSDateTime) OVER (PARTITION BY a.DeviceId, SubscriberLoginID ORDER BY CONVERT(DATETIME, GPSDateTime)) NextGPSDateTime,
    a.LocationName,
    LEAD(LocationName) OVER (PARTITION BY a.DeviceId, SubscriberLoginID ORDER BY CONVERT(DATETIME, GPSDateTime)) NextLocationName
FROM    
    tblGPSDataDetail a WITH(NOLOCK) 
JOIN
    dbo.tblDeviceMaster tdm WITH(NOLOCK) ON a.DeviceID = tdm.DeviceID 
                                         AND CityID = 3
WHERE 
    CONVERT(VARCHAR, CONVERT(DATETIME, GPSDateTime), 101) = CONVERT(VARCHAR(20), GETDATE() - 1, 101)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题