本文介紹了如何在 Laravel Eloquent 中計(jì)算價(jià)值?的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我在laravel 8中計(jì)算值時(shí)遇到問題.我想計(jì)算表中的所有值下面那個(gè)已經(jīng)進(jìn)入并且還沒有狀態(tài).如何計(jì)算laravel eloquent中沒有狀態(tài)的值,它是由member_Code分組的
I have trouble in counting values in laravel 8. I want to count all in the table below that have in and doesnt have a status out yet. How to count value that is doesnt have status out in laravel eloquent it is group by member_Code
推薦答案
你可以像這樣使用 DB::raw
進(jìn)行計(jì)數(shù):
you can count using DB::raw
like this:
$values= MyModel::query()->where('status', '!=', 'out')
->select(['member_Code',DB::raw('count(*)')]) ->groupBy('member_Code')->get();
如果要統(tǒng)計(jì)所有尚未超時(shí)的成員,可以使用distinct 方法:
if you want to count all member that don't time out yet, you can use distinct method:
$inMemebersCount= MyModel::query()->where('status', '!=', 'out')
->select('member_Code')->distinct()->count();
這篇關(guān)于如何在 Laravel Eloquent 中計(jì)算價(jià)值?的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!