Hi i have a table which includes meter reading of different meters. When i give the meter id i need to take the last 2 meter reading values . My table structure and datas are
CREATE TABLE MeterReading ( ReadingID int, MeterID int, DataCounter int, Value numeric(16,4) )
INSERT INTO MeterReading VALUES(1, 1, 1, 102.45) INSERT INTO MeterReading VALUES(2, 2, 1, 110.45) INSERT INTO MeterReading VALUES(3, 1, 2, 110.58) INSERT INTO MeterReading VALUES(4, 2, 2, 115.89) INSERT INTO MeterReading VALUES(5, 1, 4, 120.00) INSERT INTO MeterReading VALUES(6, 2, 4, 116.23)
Here i need the difference of latest (based on DataCounter) difference of Values corresponding MeterID
select top 2 * from MeterReading where MeterID = 1 order by DataCounter descI give the select query. so that i need to take the diffrence of these selected rows' Values. Always the latest value is larger