select 单据日期,金额,sum(金额) OVER(partition BY month(单据日期),销售组织 order by 单据日期) AS 累计,销售组织
from 出库实际 where YEAR(单据日期) >='2022' and 单据日期<=getdate() order by 单据日期 desc
这样写得话,到23年1月的时候就会把22年1月的加上去,请问有什么方法可以解决呢,想要实现每日累加,就是一直往后加
表结构

sql 按月统计总金额
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
1条回答 默认 最新
- wux_labs 2023-01-05 13:34关注
over里面把年份也加上。
select 单据日期,金额,sum(金额) OVER(partition BY year(单据日期),month(单据日期),销售组织 order by 单据日期) AS 累计,销售组织 from 出库实际 where YEAR(单据日期) >='2022' and 单据日期<=getdate() order by 单据日期 desc
如果有用,望采纳,谢谢!
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录