ThinkPHP5.0 模型聚合操作


1、count 統計數量,參數是要統計的字段名(可選填

//靜態調用
User::count();
User::where('status','>',0)->count();

//動態調用
$user = new User;
$user->count();
$user->where('status','>',0)->count();

2、max 獲取最大值,參數是要統計的字段名(必

//靜態調用
User::max('score');
User::where('status','>',0)->max('score');

//動態調用
$user = new User;
$user->max('score');
$user->where('status','>',0)->max('score');

3、min 獲取最小值,參數是要統計的字段名(必填)

//靜態調用
User::min('score');
User::where('status','>',0)->min('score');

//動態調用
$user = new User;
$user->min('score');
$user->where('status','>',0)->min('score');

4、avg 獲取平均值,參數是要統計的字段名(必填)

//靜態調用
User::avg('score');
User::where('status','>',0)->avg('score');

//動態調用
$user = new User;
$user->avg('score');
$user->where('status','>',0)->avg('score');

5、sum 獲取總分,參數是要統計的字段名(必填)

//靜態調用
User::sum('score');
User::where('status','>',0)->sum('score');

//動態調用
$user = new User;
$user->sum('score');
$user->where('status','>',0)->sum('score');

 

   


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM