聚合查询

 

count 总数

$userModel = new UserModel();
$sum = $userModel->
    ->where(['type' => 1])
    ->count()

 

sum 总和

$userModel = new UserModel();
$sum = $userModel->
    ->fields('balance')
    ->where(['type' => 1])
    ->sum()