Sql 按月计算的累计值总和
我在SQL Server中执行查询时,发现一个错误 “order”附近的语法不正确 我已经看到了一些关于它的问题,并对代码进行了修订,但我看不出哪里出了问题 以下是查询:Sql 按月计算的累计值总和,sql,sql-server-2008,cumulative-sum,Sql,Sql Server 2008,Cumulative Sum,我在SQL Server中执行查询时,发现一个错误 “order”附近的语法不正确 我已经看到了一些关于它的问题,并对代码进行了修订,但我看不出哪里出了问题 以下是查询: SELECT datepart(month, nota.DT_Sale_Forma_Bill_Exit) AS mon_text, sum(SUM(nota.NM_Material)) OVER (ORDER BY datepart(month,nota.DT_Sale_Forma_Bill_Exit))
SELECT
datepart(month, nota.DT_Sale_Forma_Bill_Exit) AS mon_text,
sum(SUM(nota.NM_Material)) OVER (ORDER BY datepart(month,nota.DT_Sale_Forma_Bill_Exit))
FROM
DW_DTS_Representative usuario
INNER JOIN
DIS_DTS_Invoice_Fact nota ON usuario.SK_Representative = nota.SK_Representative
INNER JOIN
DW_DTS_Operation_Nature cfop ON cfop.SK_Operation_Nature = nota.SK_Operation_Nature
INNER JOIN
DW_DTS_Emitter cli ON cli.SK_Emitter = nota.SK_Emitter
WHERE
nota.CD_Currency = '1'
AND nota.CD_Site = '001'
AND nota.DT_Sale_Forma_Bill_Exit = '2017'
AND cli.CD_Customer_Group != '16'
GROUP BY
datepart(month, nota.DT_Sale_Forma_Bill_Exit)
ORDER BY
datepart(month, nota.DT_Sale_Forma_Bill_Exit)
直到SQLServer2012年才推出,但微软网站说,它的版本从2008年开始。over条款于2005年引入,但直到2012年才支持order by with aggregates。