首页 > 其他 > 详细

laravel count的使用

时间:2018-06-12 11:16:59      阅读:258      评论:0      收藏:0      [点我收藏+]

rt

学习源头:

https://blog.csdn.net/chajinglong/article/details/51954010

四、聚合

查询构建器还提供了各种聚合方法,如统计,马克斯,min,avg和总和。

Using Aggregate Methods

复制代码代码如下:

$users = DB::table(‘users‘)->count();
$price = DB::table(‘orders‘)->max(‘price‘);
$price = DB::table(‘orders‘)->min(‘price‘);
$price = DB::table(‘orders‘)->avg(‘price‘);
$total = DB::table(‘users‘)->sum(‘votes‘);

 

Raw Expressions

有时您可能需要使用一个原始表达式的查询。这些表达式将注入的查询字符串,所以小心不要创建任何SQL注入点!创建一个原始表达式,可以使用DB:rawmethod:

Using A Raw Expression

 

复制代码代码如下:


$users = DB::table(‘users‘)
->select(DB::raw(‘count(*) as user_count, status‘))
->where(‘status‘, ‘<>‘, 1)
->groupBy(‘status‘)
->get();

laravel count的使用

原文:https://www.cnblogs.com/djwhome/p/9172089.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!