Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在尝试获取对象中包含的变量的总和,但我不知道该怎么做。我知道这不是很清楚,所以这里有一个例子。
我正在请求从一位用户那里获得所有折扣。我现在想得到他所有折扣的总和。在 SQL 中,它将是:
SELECT SUM(c.discount_price) AS SumDiscounts FROM my_table c GROUP BY c.user_id
我怎样才能在推进中做到这一点?
试试这个查询:
$collection = MyTableQuery::create() ->withColumn('SUM(c.discount_price)', 'SumDiscounts') ->groupByUserId() ->find();