Sql 尝试计算运行总数会使所有内容都为0
我有这个疑问Sql 尝试计算运行总数会使所有内容都为0,sql,amazon-redshift,Sql,Amazon Redshift,我有这个疑问 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
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
s,但在原始查询中你看不到它们。换句话说,您有一个查询,其中没有orderby,因此结果集中的排序可以是任何内容
尝试使用过滤器:
with tab1(A) as
.....
select A, sum(A) over (order by A rows unbounded preceding)
from tab1
where A > 0;
你能举一个完整的例子吗?你在用亚马逊红移吗?