In my database I'm storing data as below:
id amt
-- -------
1 100
2 -50
3 100
4 -100
5 200
I want to get output like below
id amt balance
-- ----- -------
1 100 100
2 -50 50
3 100 150
4 -100 50
5 200 250
How to do with in django orm
sum()as a window function:SELECT id, amt, sum(amt) OVER (ORDER BY id) AS balance FROM yourtable(At least in modern versions of sqlite). Dunno about with an ORM, though.Model.objects.raw("some_sql")