我有这样的疑问
with tab1(A) as
.....
select A from tab1;
这给我返回了几行,如
1.0
2.0
3.0
4.0
现在我把这个查询改为
with tab1(A) as
.....
select
A,
sum(A) over(order by A rows unbounded preceding)
from tab1;
输出变成了
0, 0
0, 0
0, 0
0, 0
我希望得到的是
1.0, 1.0
2.0, 3.0
3.0, 6.0
4.0, 10.0
我的结果怎么都变成0了?
列表中的 0
的数据可能已经在数据中了,但你只是在原始查询中没有看到它们。 换句话说,你的查询中并没有看到 ORDER BY
所以结果集中的排序可以是任何东西。
试试使用过滤器。
with tab1(A) as
.....
select A, sum(A) over (order by A rows unbounded preceding)
from tab1
where A > 0;