laravel5.5 用一条sql统计count(*)价格和订单数

例如:

$order = DB::table('third_orders')->select(DB::raw('count(*) as count_order, sum(order_price) as count_price'))

    ->where(['third_key' => $third_key])->get()->sum('order_price');


或者:

$order = DB::table('third_orders')->where(['third_key' => $third_key])->count();//总订单数

//  $price = DB::table('third_orders')->where(['third_key' => $third_key])->sum("order_price");//总价格

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • rljs by sennchi Timeline of History Part One The Cognitiv...
    sennchi阅读 7,418评论 0 10
  • Overview The ccxt library is a collection of available cr...
    郭蝈儿蝈儿阅读 3,786评论 0 1
  • 这一篇最主要是记录下命令,方便以后查找 使用Mysql 创建数据库 create database mysql_t...
    Treehl阅读 592评论 0 0
  • 中午几点休息合适 文/我心我愿秀 时间:2017年5月4日 我们一般会花半个小时到一个小时吃饭,刚吃完饭,马上就去...
    我心我愿秀阅读 432评论 0 3
  • 感恩上天给予父母健健康康的身体,感恩父母给予我生命,感恩父母养育之恩,感恩父母的包容,感恩今天公交车驾驶员安全送到...
    26a658189666阅读 142评论 0 2