Extract specific row - SelectCommand
I have 5 rows of data coming into my database every 2 hours from a GSM modem and I require only the last (latest) row of data as thats the only relevant one but need all of the data for a chart...
Is there a way of using something to only recall one row after every fourth.
1pm 23, 25, 20,99,21
3pm 34, 56, 55, 65, 30
only showing 21 and 30 in data.
WITH NumberedRows AS ( SELECT Serial, DeviceLevel, ROW_NUMBER() OVER (ORDER BY DateReceived DESC) AS RowNumber FROM TBLReadings ) SELECT * FROM NumberedRows WHERE RowNumber % 5 = 0
Use the following SQL statement to fetch the required data:
select top (1) from your table order by DateTimeField Desc
It's not so many information, need more for the exact solution.
But if the timestamp of the records differ and you already can select the 5 for 1pm and 3pm, then you can try something similar in the where clause:
timestamp = select max(timestamp) from (the_5_recs_for_the_given_intervall)
Hope you understand what I want to say!