Skip to content

Instantly share code, notes, and snippets.

@bjartwolf
Created January 24, 2016 11:48
Show Gist options
  • Save bjartwolf/492c2a47e992382ad2f4 to your computer and use it in GitHub Desktop.
Save bjartwolf/492c2a47e992382ad2f4 to your computer and use it in GitHub Desktop.
SELECT p.UpdatedUtc, p.LastReadTimeStampUtc, p.LastReadMeterValue, p.Unit, p.MeterPointId
FROM (SELECT UpdatedUtc,
LastReadTimeStampUtc,
LastReadMeterValue,
Unit,
MeterPointId,
rn = ROW_NUMBER() OVER (PARTITION BY MeterPointId ORDER BY UpdatedUtc DESC)
FROM AbsoluteMeterReadings
WHERE UpdatedUtc <= @until )as p
WHERE rn=1
ORDER BY p.UpdatedUtc
OFFSET @offset ROWS
FETCH NEXT @pagesize ROWS ONLY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment