SQL求月份累计

1月100,2月200,3月100,4月200.统计如下效果:1月100,2月300,3月500,4月600.【就是每月统计一次前面所有的月的总额】

直接上sql啦

select month,amount,sum(amount) over(order by month asc) from expense;

select t.* ,(select sum(amount) from expense where month <= t.month) from expense t;

两种sql写法在oracle中都是支持的,第二种写法在spark sql 不支持。

赶紧记下了,以免问起被怼的哑口无言。

猜你喜欢

转载自blog.csdn.net/qq_32445015/article/details/102538313