I have a query as follows
SELECT *
FROM [VNPoller].[DBA].[uccpu1mUTMStats]
WHERE resid in (SELECT resid
FROM [VNPoller].[DBA].[ResourceView]
WHERE Dataset in
(SELECT dataset
FROM [VNPoller].[DBA].[DatasetTable]
WHERE datasetDescription LIKE '%CPU%'
)
AND devID = '1157')
order by dttm desc
I have a list of devices that are polled every 5 mins, each poll adds a new row to the table with latest values, Im this case I am looking at CPU. However a device may have multiple CPU's so I may have 4 values for CPU over the last 5 mins, so 4 new entries in the DB. Each CPU has a unique resID. I need to see the Max (latest dttm value for each of the 4 resides. My query returns all the rows for the entire day. Or I can get is to display just one value using the max(dttm) but I need the other 3 values. Maybe a picture can help explain. Many Thanks for anyone who can offer some help here
Im only interested in seeing the top 4 items( the max (dttm) for each of the different resides. the rest are duplicated but for early time stamps
Sample data from uccpu1mUTMStats
table which actually contains thousands of rows:
dttm resID cpmCPUTotalMonIntervalValue
2018-09-28 22:10:00.000 294324 0
2018-09-28 22:10:00.000 294325 0
2018-09-28 22:10:00.000 294432 1
2018-09-28 22:10:00.000 294482 0
2018-09-28 22:10:01.000 294415 0
2018-09-28 22:10:01.000 294433 1
2018-09-28 22:10:01.000 294669 0
2018-09-28 22:10:02.000 294396 0
2018-09-28 22:10:02.000 294397 0
2018-09-28 22:10:02.000 294416 0
2018-09-28 22:10:03.000 294417 0
2018-09-28 22:10:03.000 294434 1
2018-09-28 22:10:03.000 294435 1
2018-09-28 22:10:04.000 294398 0
2018-09-28 22:10:04.000 294399 0
2018-09-28 22:10:04.000 294418 0
2018-09-28 22:10:05.000 294400 0
2018-09-28 22:10:05.000 294419 0
The expected results are:
dttm resID cpmCPUTotalMonIntervalValue
2018-10-05 15:21:37.000 294100 21
2018-10-05 15:21:24.000 294099 23
2018-10-05 15:20:53.000 294098 19
2018-10-05 15:20:16.000 294097 23