第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 Laravel 中使用了 groupby 的總和

在 Laravel 中使用了 groupby 的總和

PHP
呼喚遠(yuǎn)方 2022-01-02 16:22:08
我已經(jīng)通過(guò)inventory_id 對(duì)列價(jià)格組求和。此外,我需要計(jì)算總價(jià)。$record = ProductDetails::with('inventoryName')->whereDate('created_at', '=', date($date))      ->select('inventory_id',DB::raw('sum(price) as item_price'),DB::raw('sum(quantity) as quantity'))->groupBy('inventory_id')->get();我的輸出是:[  {    inventory_id: 9,    item_price: 30,    quantity: 30,    inventory_name: [      {        id: 9,        name: "sugar"      }    ]  },  {    inventory_id: 10,    item_price: 70,    quantity: 70,    inventory_name: [      {        id: 10,        name: "oil"      }    ]  }]現(xiàn)在我需要計(jì)算總價(jià)。如何做到這一點(diǎn)。
查看完整描述

1 回答

?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

您可以使用Laravel Collection: SUM 方法。


1. If $record is already a collection:

echo $record->sum('item_price');


2. If $record is an array.

$collection = collect($record);

$collection->sum('item_price');


查看完整回答
反對(duì) 回復(fù) 2022-01-02
  • 1 回答
  • 0 關(guān)注
  • 300 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)