SQLite Forum

Using windows function
Login

Using windows function

(1) By anonymous on 2020-09-10 15:31:31 [link]

I have a table with 4 columns. Namely accit qtyd qtyr run total
I have tried this so far 
SUM(qtyd-qtdr)FILTER (WHERE t1.accit = t1min.accit)OVER (ORDER BY t1.accit ROWS UNBOUNDED PRECEDING)AS RUNtotal
The problem is that it is doing a running total but for all. I need it to do per accit and then the next accit

1.  5. 2.  3
1.  2. 1.  4
2.  5. 1   8 ( here it should be 4 as it is a new accit)

Please help as to where I am going wrong.

(2) By David Raymond (dvdraymond) on 2020-09-10 15:48:25 in reply to 1 [link]

I think you need a "partition by" in there
... over (partition by t1.accit order by...
...but I'm not the most familiar with window functions

(3) By anonymous on 2020-09-10 15:59:28 in reply to 2

Thanks a lot.It worked. Instead of Order by changed to Partition by.