I'm trying to get the sum of variables contained in my object, and I don't know how to do it. I know it's not very clear, so here is an example.
I'm doing a request to obtain all discounts from one User. I now want to get the sum of all the discounts he had. In SQL, it would be:
SELECT SUM(c.discount_price) AS SumDiscounts FROM my_table c GROUP BY c.user_id
How can I do it in propel?
Try this query:
$collection = MyTableQuery::create()
->withColumn('SUM(c.discount_price)', 'SumDiscounts')
->groupByUserId()
->find();