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