2014-07-04 54 views
0

我需要創建一個以六個月爲間隔的平均值,直到數據庫的開始時間。對於我來說,我想這個答案會是類似的。多個六個月期間的平均值

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來做到這一點,如果任何人有任何想法做到這一點。

任何幫助將不勝感激。

回答

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 
+0

工作。謝謝 – Akameriadoc