本文介紹了如何在 Laravel Eloquent 中計算價值?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我在laravel 8中計算值時遇到問題.我想計算表中的所有值下面那個已經進入并且還沒有狀態.如何計算laravel eloquent中沒有狀態的值,它是由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
進行計數:
you can count using DB::raw
like this:
$values= MyModel::query()->where('status', '!=', 'out')
->select(['member_Code',DB::raw('count(*)')]) ->groupBy('member_Code')->get();
如果要統計所有尚未超時的成員,可以使用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();
這篇關于如何在 Laravel Eloquent 中計算價值?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!