我要基于当前月份每季度显示最近12个月数据。 例如,当前月份为六月,则我的数据应显示4个分组集JUNE-MAY-APRIL,JUNE-MAY-APRIL,DEC-NOV-OCT,SEPT-AUG-JULY
Below is the sql query i am try
DECLARE @ANYDATE DATETIME
SET @ANYDATE=GETDATE()
SELECT TOP 20 DATePART(MONTH,@ANYDATE) [MONTH],
DATePART(QUARTER,@ANYDATE) [Quarter], COUNT(1) [ACount]
FROM ACTIVITY ACC
INNER JOIN Accounts A ON ACC.Relatedtoid = A.ACCOUNTID
AND ACC.OWNERID = A.OWNERID
WHERE ACC.layoutid = 1015
AND ACC.ownerid = 402
AND A.LAYOUTID IN (
104442
,104451
,104436
)
GROUP BY
DATePART(MONTH,ACC.CREATEDON),DATePART(QUARTER,ACC.CREATEDON)
ORDER BY 1,2
OUTPUT OF CURRENT QUERY