I have a table like this.
deviceid temperature timestamp
1 35 222222222
1 36 333333333
2 35 222222222
2 35 333333333
2 35 444444444
3 37 222222222
3 39 333333333
3 41 444444444
Say I need:
200 rows that have deviceid 1
200 rows that have deviceid 2
200 rows that have deviceid 3.
But I need the 200 most recent rows of each, timestamp.
How do I limit the results to 200 of each distinct deviceid's most recent timestamped temperatures?
I kept finding answers that use TOP, MAX, and DISTINCT, but I can't seem to put it all together.