1

我有一些我正在尝试报告的性能数据。

我需要输出给我每个计数器每月每周的平均值。

这是使用日期/时间字段的查询(即'2012-01-01 00:00:00.750')

SELECT MachineName ,
        CounterName ,
        InstanceName, 
        CounterValue,
        ObjectName,
        CounterDateTime 
FROM    dbo.CounterDetails cdt

        INNER JOIN dbo.CounterData cd ON cdt.CounterID = cd.CounterID
        INNER JOIN DisplayToID d ON d.GUID = cd.GUID

WHERE   MachineName = '\\SERVER1'

AND CounterDateTime BETWEEN '2012-01-01 00:00:00.750' AND '2012-01-31 23:59:00.750'
GROUP BY ObjectName, CounterName, InstanceName, CounterValue, CounterDateTime, MachineName
ORDER BY CounterDateTime

感谢回复

4

1 回答 1

0

I rearranged your fields as it don't make sense to me, but you can try something this:

SELECT  MachineName
        , ObjectName
        , InstanceName
        , CounterName
        , DATEPART( YEAR, CounterDateTime ) As YearNo
        , DATEPART( MONTH, CounterDateTime ) As MonthNo
        , DATEPART( WEEK, CounterDateTime ) AS WeekNo
        , AVG(CounterValue) AS avgCounterValue
FROM    dbo.CounterDetails cdt
        INNER JOIN dbo.CounterData cd
            ON cdt.CounterID = cd.CounterID
        INNER JOIN DisplayToID d
            ON d.GUID = cd.GUID
WHERE       MachineName = '\\SERVER1'
            AND CounterDateTime BETWEEN '2012-01-01 00:00:00.750' AND '2012-01-31 23:59:00.750'
GROUP BY    MachineName, ObjectName, InstanceName, CounterName
            , DATEPART( YEAR, CounterDateTime )
            , DATEPART( MONTH, CounterDateTime )
            , DATEPART( WEEK, CounterDateTime )
ORDER BY    MachineName, ObjectName, InstanceName, CounterName
            , DATEPART( YEAR, CounterDateTime )
            , DATEPART( MONTH, CounterDateTime )
            , DATEPART( WEEK, CounterDateTime )

If your table is large, you might want to create an index on [MachineName] and [CounterDateTime]

于 2012-12-27T07:48:57.060 回答