多个六个月期间的平均值

时间:2014-07-04 00:41:57

标签: sql reporting-services

我需要创建一个平均六个月的间隔,直到数据库的开始时间。一周我有这个,我想答案会是类似的。

SELECT AVG(q1.Entry1) as AvgPerWeek
FROM (SELECT COUNT(TestID) as Entry1, DATEPART(wk, TestDate) as Wk
FROM Table1
GROUP BY Year(TestDate), DATEPART(wk, TestDate))q1

我的第二选择是尝试通过SSRS尝试这样做,如果有人对此有任何想法。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如果没有可用的功能发明一个!我用CASE:

SELECT AVG(q1.Entry1) as AvgPerWeek
FROM (SELECT COUNT(TestID) as Entry1, Year(TestDate),
      CASE WHEN DATEPART(month, TestDate) between 1 AND 6 
       THEN 'first half' ELSE 'second half' END as term
      FROM Table1
      GROUP BY Year(TestDate), 
               CASE WHEN DATEPART(month, TestDate) between 1 AND 6 
                    THEN 'first half' ELSE 'second half' 
               END
     ) q1