2015-07-04 269 views
1

我想統計包括當前月在內的最近12個月的按月記錄數。按日期計算大於X(日,月,年)的月份記錄

這工作,直到我們得到7月,當它結合了數據,2014年7月至2015年

SELECT Max(MonthName(DatePart("m",[FormSentOff]),True)) AS Mth, 
     Count(tblDisclosure.ID) AS CountOfID 
FROM tblDisclosure 
GROUP BY DatePart("m",[FormSentOff]) 
HAVING (((DatePart("m",[FormSentOff])) Is Not Null) 
    AND ((Max(MonthName(DatePart("m",[FormSentOff]),True))) Is Not Null)) 
ORDER BY Max(tblDisclosure.FormSentOff), Max(MonthName(DatePart("m",[FormSentOff]),True));` 

我曾試圖建立沒有成功的子查詢和也試圖操縱以各種方式上面的代碼沒有成功。

回答

3

航代號:

SELECT 
    Format(Max(FormSentOff),"mmm") as Mth, 
    Count(*) as CountOfRecords 
FROM tblDisclosure 
WHERE FormSentOff >= DateAdd("m",-11,DateSerial(Year(Date()),Month(Date()),1)) 
GROUP BY Year(FormSentOff), Month(FormSentOff) 
ORDER BY Year(FormSentOff), Month(FormSentOff) 
+0

好極了!非常感謝你! –

相關問題