Im having a hard time working out a proper DQL to generate cumulative sum. I can do it in plain SQL but when it comes to DQL i cant get hold of it.
Here is how it looks 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
Thanks
Hey, I have check the documentation for Doctrine 1.2, and the way to create the query is (put attention on the alias):
To output the SQL query created:
To execute the statement:
And to access the retrieved data is:
Read the rest of the documentation at Group By Clauses.
You just specify the sum in your select part of the DQL:
Check out this page in the Doctrine documentation for more info.