欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

tp5 sum某個(gè)字段相加得到總數(shù)的例子

 更新時(shí)間:2019年10月18日 09:22:22   作者:我是高手高手高高手  
今天小編就為大家分享一篇tp5 sum某個(gè)字段相加得到總數(shù)的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

方法 說(shuō)明

count 統(tǒng)計(jì)數(shù)量,參數(shù)是要統(tǒng)計(jì)的字段名(可選)

max 獲取最大值,參數(shù)是要統(tǒng)計(jì)的字段名(必須)

min 獲取最小值,參數(shù)是要統(tǒng)計(jì)的字段名(必須)

avg 獲取平均值,參數(shù)是要統(tǒng)計(jì)的字段名(必須)

sum 獲取總分,參數(shù)是要統(tǒng)計(jì)的字段名(必須)

用法示例:

獲取用戶數(shù):

Db::table(‘think_user')->count(); 
// 助手函數(shù) 
db(‘user')->count();

或者根據(jù)字段統(tǒng)計(jì):

Db::table(‘think_user')->count(‘id'); 
// 助手函數(shù) 
db(‘user')->count(‘id');

獲取用戶的最大積分:

Db::table(‘think_user')->max(‘score'); 
// 助手函數(shù) 
db(‘user')->max(‘score');

獲取積分大于0的用戶的最小積分:

Db::table(‘think_user')->where(‘score>0')->min(‘score'); 
// 助手函數(shù) 
db(‘user')->where(‘score>0')->min(‘score');

獲取用戶的平均積分:

Db::table(‘think_user')->avg(‘score'); 
// 助手函數(shù) 
db(‘user')->avg(‘score');

統(tǒng)計(jì)用戶的總成績(jī):

Db::table(‘think_user')->sum(‘score'); 
// 助手函數(shù) 
db(‘user')->sum(‘score');

案例

//統(tǒng)計(jì)字段tuition 學(xué)費(fèi)的總分?jǐn)?shù)
$tuition_total= db('student')->where($where)->sum('tuition');;
$count = count($rs1);//取得記錄集總條數(shù)
jsonStudent(0,$tuition_total,'數(shù)據(jù)返回成功',$count,$rs); 

以上這篇tp5 sum某個(gè)字段相加得到總數(shù)的例子就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評(píng)論