我想根据年份月份下拉框求出当月的数据和上月数据,年份下拉框是year,月份下拉框是month 写了个当月的,可能有点问题,应该怎么改啊 WITH A AS ( SELECT SUM ( d.fundsum ) AS TRADITIONGETMONEY FROM DBO.ONCONTRACT C LEFT JOIN DBO.ONCONTRACTFEE AS D ON C.CODE = D.CONTRACTCODE WHERE CODE NOT LIKE ( '%总包%' ) AND DATEDIFF( MONTH, D.FUNDDEALDATE, GETDATE( ) ) = 0 ), B AS ( SELECT SUM ( d.fundsum ) AS TRADITIONGETMONEY FROM ODBusiness.DBO.ONCONTRACT C LEFT JOIN ODBusiness.DBO.ONCONTRACTFEE AS D ON C.CODE = D.CONTRACTCODE WHERE CODE NOT LIKE ( '%总包%' ) AND DATEDIFF( MONTH, D.FUNDDEALDATE, GETDATE( ) ) = 1 ) SELECT ( A.TRADITIONGETMONEY- B.TRADITIONGETMONEY ) / NULLIF ( B.TRADITIONGETMONEY, 0 ) FROM A,B |