I've got a fairly straightforward (I thought) data request from a very long table in SQL Server.
The table TMLogs
contains thousands of data samples from machinery sensors connected to generators. These generators are connected to sensors that provide a snapshot of data on key generator performance components: RPM, Temperature, Sample Time, etc. The data snapshots are taken every 5 seconds, then stored in a SQL Server database. The generators are in different time zones, and the clocks aren't very accurate (+/- 10) minutes.
The columns look something like this:
Generator Name | Generator State | Fuel Tank Reading | Output (watts) | Sample Time (YYYY-DD-MM HH:MM:SS) | Engine Temp (F°) | Output Descriptor|....
My goal is to retrieve only the most recent sample that each generator has given.
Selecting the TOP
X values only gives the generators in the eastern time zone, or the ones that have system clocks that are ahead of official time.
So, given the criteria Generator Name
, how would I retrieve the newest data sample that each generator has stored?