我很难制定出适当的 DQL 来生成累积总和。我可以用普通的 SQL 来做,但是当涉及到 DQL 时,我无法掌握它。
下面是它在 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
谢谢