I have the following table in Teradata:
ranked | data_val
-------- ----------
1 | 100
2 | 30
2 | 20
2 | 70
I want the following table, where avg_val
is the rolling average of data_val
values ordered by increasingly ascending ranked
values:
ranked | avg_val
------ ---------
1 | 100
2 | 55
I try using:
SELECT
ranked
, AVERAGE(data)val) OVER (
PARTITION BY NULL
ORDER BY ranked ASC
ROWS UNBOUNDED PRECEDING
) AS avg_val
FROM tbl
;
but I get this:
ranked | avg_val
------ ---------
1 | 100
2 | 65
2 | 50
2 | 55
which is not what I want.
How do I return the desired output?