I find it difficult to find the correct DQL to generate a cumulative sum. I can do this in plain SQL, but when it comes to DQL, I can't hold it.
Here's what it looks like in SQL:
SELECT s.name, p.date_short, p.nettobuy, (select sum(pp.nettobuy) as sum from price pp where pp.stock_id = p.stock_id and p.broker_id = pp.broker_id and pp.date_short <= p.date_short) as cumulative_sum FROM price p left join stock s on p.stock_id = s.id group by p.stock_id, p.date_short order by p.stock_id, p.date_short
code>
thanks
phpworm
source share