5
查询生成器,我将如何使用查询生成器在Laravel生成以下SQL语句:如何使用与SUM()列和GROUPBY
SELECT costType, sum(amountCost) AS amountCost
FROM `itemcosts`
WHERE itemid=2
GROUP BY costType
我已经试过几件事情,但我不能让sum()
列与重命名一起使用。
我最新的代码:
$query = \DB::table('itemcosts');
$query->select(array('itemcosts.costType'));
$query->sum('itemcosts.amountCost');
$query->where('itemcosts.itemid', $id);
$query->groupBy('itemcosts.costType');
return $query->get();