Hi,
I'm trying to find the cumulative sum of some values using the query below
select number,sum(number) over (order by number desc) as cumsum
from
(
select 100 as number
union all
select 50
union all
select 50
union all
select 1
union all
select 1
union all
select 1
) as t1
The expected result is:
number cumsum
100 100
50 150
50 200
1 201
1 202
1 203
Presto Output is:
number cumsum
100 100
50 200
50 200
1 203
1 203
1 203
Presto calculates and writes the same cumulative sum value for the same numbers. I've searched through the issues and internet but couldn't find a similar issue. What may be the problem?
Presto documentation (https://prestodb.io/docs/current/functions/window.html) states that if not given, over clause defaults to RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW which is different than ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW
select number,sum(number) over (order by number desc rows between unbounded preceding and current row) as cumsum
from
(
select 100 as number
union all
select 50
union all
select 50
union all
select 1
union all
select 1
union all
select 1
) as t1
gives the expected result
Most helpful comment
Presto documentation (https://prestodb.io/docs/current/functions/window.html) states that if not given, over clause defaults to
RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROWwhich is different thanROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROWgives the expected result