Hey guys, I'm having a helluva time getting a SQL query to pull back the data I need.
The boss wants to know what the max CPU utilization is on any single app server for every hour of the day for a given date.
So, the query should bring back the date/time and maxvalue for 00 (midnight), 01, 02, 03, etc., and return only 24 rows, each one showing the max CPU utilization (the maxvalue column).
There are 8 app servers. This query brings back the entries every hour, but for all 8 app servers...
And the results are...
I clipped off hours 3am through 11pm - you get the idea.
So for the midnight hour the max is 2, 1am it's 2, 2am it's 3.
So I'd like to get results like so...
The resid column is a reference to a server name in the ManagedObjects table.
I don't need that in the results but just selecting it out of curiosity.
I've been googling and querying all day long and haven't made any progress.
Every GROUP BY clause and HAVING clause I've tried, I've had nothing but errors.
Any ideas?
The boss wants to know what the max CPU utilization is on any single app server for every hour of the day for a given date.
So, the query should bring back the date/time and maxvalue for 00 (midnight), 01, 02, 03, etc., and return only 24 rows, each one showing the max CPU utilization (the maxvalue column).
There are 8 app servers. This query brings back the entries every hour, but for all 8 app servers...
Code:
select distinct dateadd(s,c.ARCHIVEDTIME/1000,'19700101') as DateAndTime
,c.resid
,c.maxvalue
from CPU_MinMaxAvgData c
inner join ManagedObject m on m.resourceid = c.resid
where c.resid in (select resourceid from ManagedObject where displayname like 'app_' and type='Linux')
and dateadd(s,c.ARCHIVEDTIME/1000,'19700101') between '2015-07-08 00:00:00.000'
and '2015-07-08 23:01:00.000'
And the results are...
Code:
DateAndTime resid maxvalue
2015-07-08 00:00:00.000 80000818 2
2015-07-08 00:00:00.000 80000831 1
2015-07-08 00:00:00.000 80000844 2
2015-07-08 00:00:00.000 80000857 2
2015-07-08 00:00:00.000 80000870 2
2015-07-08 00:00:00.000 80000883 2
2015-07-08 00:00:00.000 80000896 2
2015-07-08 00:00:00.000 80000909 2
2015-07-08 01:00:00.000 80000818 2
2015-07-08 01:00:00.000 80000831 2
2015-07-08 01:00:00.000 80000844 2
2015-07-08 01:00:00.000 80000857 2
2015-07-08 01:00:00.000 80000870 2
2015-07-08 01:00:00.000 80000883 2
2015-07-08 01:00:00.000 80000896 2
2015-07-08 01:00:00.000 80000909 2
2015-07-08 02:00:00.000 80000818 2
2015-07-08 02:00:00.000 80000831 2
2015-07-08 02:00:00.000 80000844 3
2015-07-08 02:00:00.000 80000857 2
2015-07-08 02:00:00.000 80000870 2
2015-07-08 02:00:00.000 80000883 2
2015-07-08 02:00:00.000 80000896 2
So for the midnight hour the max is 2, 1am it's 2, 2am it's 3.
So I'd like to get results like so...
Code:
2015-07-08 00:00:00.000 80000818 2
2015-07-08 01:00:00.000 80000909 2
2015-07-08 02:00:00.000 80000844 3
The resid column is a reference to a server name in the ManagedObjects table.
I don't need that in the results but just selecting it out of curiosity.
I've been googling and querying all day long and haven't made any progress.
Every GROUP BY clause and HAVING clause I've tried, I've had nothing but errors.
Any ideas?