SQL Server 中有一个查询:
SELECT
Segment_ID = Segment_ID.Segment_ID,
GEOMETRY::STGeomFromText(Track.Track.STAsText(),4326) as the_geom,
a.NumAll,
a.AverageDailyIntens,
a.AverageDailyIntensCar,
a.Loading
FROM dbo.Segment_ID
RIGHT JOIN Road ON Segment_ID.Road_ID = Road.Road_ID
LEFT JOIN Track ON Segment_ID.Segment_ID = Track.Segment_ID
outer apply (select top 1 Intensity.NumAll,Intensity.AverageDailyIntens,Intensity.AverageDailyIntensCar,Intensity.Loading
from Intensity
where Segment_ID.Segment_ID = Intensity.Segment_ID
ORDER BY Intensity.NumAll) a
它工作正常,但不是我想要的。它给了我第一排Intensity
,Segment_ID.Segment_ID = Intensity.Segment_ID
但我想拿最新排。
在表中Intensity
,我有日期列,日期如下2009-02-20 15:00:00.000
。
我怎样才能Segment_ID
用最新的日期排到需要的位置?