lag(理论库存) over (partition by销售客户,品规全称 order by substring (年月,1,4),substring (年月,6,2)) as 期初数量
sum(d.inn_num-c.out_num)over (partition by substring(c.[年月],1,4),c.[销售客户],c.[品规全称] order by substring(c.[年月],6,2)) as '理论库存'
使用了开窗sum()over(partition by order by)函数,然后根据我自己的需求利用lag函数进行数据变换,得到最终结果