本文主要是介绍hyperf框架聚合查询多字段查询,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
hyperf框架聚合查询(count, max, min, avg, sum)基础使用方法是单个查询的
$count = Db::table('user')->count('id');
$count = Db::table('user')->sum('number');
需要查询多个字段,如sql语句:
select sum(number),sum(number1),sum(number2),sum(number3) from user
hyperf框架内使用 first() 实现同时使用聚合查询多个字段
$count = DB::table('user')->where('p_id', '=', 1)->first(array(DB::raw('SUM(number) as number'),DB::raw('SUM(number1) as number1'),DB::raw('SUM(number2) as number2'),DB::raw('COUNT(id) as count'),));
结果如下,返回一个数组
$count =["number"=>"3595.0000","number1"=>"12187.0500","number2"=>"12187.0500","count"=>841]
这篇关于hyperf框架聚合查询多字段查询的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!