WIITH cteEventOrdered AS
(
SELECT Device,
Loc,
CaptureTime,
Here,
ROW_NUMBER() OVER(PARTITION BY Device ORDER BY CaptureTime DESC) AS RowNumber
FROM dbo.vrtEvents
)
SELECT *
FROM cteEventOrdered
WHERE RowNumber = 1
AND Device = 808 --optional
If you have two rows:
808,20:38:21,0
808,11:11:11,1
The max time is 20:38:21 and the max here is 1.
>>HAVING (Device = Device)
I don't know what this is supposed to be doing. Just because you have a GROUP BY, you don't have to have a HAVING.