我是laravel的新手,仍然在开始执行查询。我坚持这个我无法弄清楚的查询。
Models: Flag -> Quote -> QuoteItems
1 - Quotes has many QuoteItems | QuoteItems has One Quote
2 - Each Quote has one Flag(e.g accepted, rejected)
1- QuoteItems contains Profit and Price fields.
我需要所有与一个标志相关的引号的SUM(利润)和SUM(价格)。
答案 0 :(得分:0)
您可以使用以下查询:
// Sum of price
$totalPrice= Quote->groupBy(' Flag')->sum('Price');
// Sum of profit
$totalProfit = Quote->groupBy('Flag')->sum('Profit');