add batch remove batch split batch comment selection show hidden batches hide batch highlight batch
db<>fiddle
donate feedback about
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
create table t as
select 1 as id, date('2020-01-02') as date, 0.00 as dividends_received_value union all
select 2 as id, date('2020-01-03') as date, 1.30 as dividends_received_value union all
select 3 as id, date('2020-01-04') as date, 0.45 as dividends_received_value
Records: 3  Duplicates: 0  Warnings: 0
select t.*,
sum(dividends_received_value) over (order by date
range between interval 1 year preceding and current row
) as trailing_12_month
from t;
id date dividends_received_value trailing_12_month
1 2020-01-02 0.00 0.00
2 2020-01-03 1.30 1.30
3 2020-01-04 0.45 1.75
select t.date, sum(dividends_received_value) as on_day,
sum(sum(dividends_received_value)) over (order by date
range between interval 1 year preceding and current row
) as trailing_12_month
from t
group by t.date;
date on_day trailing_12_month
2020-01-02 0.00 0.00
2020-01-03 1.30 1.30
2020-01-04 0.45 1.75