---------------------------------------------------------------------------------------------------------------
------------------------------------------------ AUSEVICH.RU --------------------------------------------------
-- http://ausevich.ru/ekspert/ispolzovanie-dannyh-poluchennyh-sborshhikom-dannyh-i-zapisannyh-v-sql-server   --
---------------------------------------------------------------------------------------------------------------

SELECT  
    cdet.MachineName,
    cdet.CounterName,
    cdet.InstanceName,
    MIN(cdata.CounterValue) AS minValue,
    MAX(cdata.CounterValue) AS maxValue,
    AVG(cdata.CounterValue) AS avgValue,
    d.DisplayString
FROM    
	dbo.CounterDetails as cdet
        INNER JOIN dbo.CounterData as cdata 
			ON cdet.CounterID = cdata.CounterID
        INNER JOIN dbo.DisplayToID as d 
			ON d.GUID = cdata.GUID
WHERE
	cdata.CounterDateTime >= '2017-10-23 17:30:00'
		AND cdata.CounterDateTime <= '2017-10-23 17:35:00'
GROUP BY 
	MachineName,
    CounterName,
    InstanceName,
    DisplayString 