关于 t-sql SUM func 的奇怪 ssms 结果,无法弄清楚

strange ssms results about t-sql SUM func, couldn't figure out

我在学习t-sql window函数的时候发现了一些奇怪的地方,这里是正常的代码,很简单。

然后我尝试删除 window 框架子句并得到相同的结果。

任何人都可以解释为什么第二个结果,谢谢。

第二个查询returns相同的结果,因为"range between unbounded preceding and current row"是默认的框架,正如你在documentation中看到的那样,你的[=16]中没有重复的行=](即具有相同 empid 和 ordermonth 的多行)。

If ROWS/RANGE is not specified but ORDER BY is specified, RANGE UNBOUNDED PRECEDING AND CURRENT ROW is used as default for window frame.