SQL server如何查询近12个月数据 不要写死,还要区分今年和去年数据 SELECT '合同金额' AS 合同金额, inputtime, CONTRACTSUM FROM ( SELECT CONVERT ( VARCHAR ( 7 ), [INPUTTIME], 120 ) AS INPUTTIME, SUM ( CONTRACTSUM ) AS CONTRACTSUM FROM DBO.ONCONTRACT WHERE DATEDIFF( MONTH, INPUTTIME, GETDATE( ) ) <= 12 GROUP BY CONVERT ( VARCHAR ( 7 ), [INPUTTIME], 120 ) ) AS A ORDER BY 2 |