0

This is my table

id daily    pre_daily  created_at
1  2000     34.50      2019-01-01 14:08:45
2  2450     30.4       2019-01-02 14:08:45
3  3500     33.7       2019-01-03 14:08:45

I want to generate the following output

id  daily  accumulation
1   2000   2000
2   2450   4450
3   3500   7950

How can I make calculations like this ? please help I want my data to recap for one month with calculations like this

Ada
  • 23
  • 2

1 Answers1

0

You can use a correlated subquery

select t.id, t.daily,
       (select sum(daily) from tab where id <= t.id ) as accumulation
  from tab t
 order by t.id;

id  daily  accumulation
1   2000   2000
2   2450   4450
3   3500   7950

Demo

P.S. If your version is 8-, then you cannot use windows analytic functions.

Barbaros Özhan
  • 59,113
  • 10
  • 31
  • 55