Laravel count的使用

聚合方法

Laravel查询构建器提供了各种聚合方法

$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

有时可能需要使用一个原始表达式的查询,可以使用DB:raw方法

$patch_stat = DB::table('app_version_patchs')
    ->select(DB::raw('count(*) as patch_count'))
    ->where('curr_version_id', $latest_version->id)->get()->first();

$user_stat = DB::table('users')
    ->select(DB::raw('count(*) as user_count, status'))
    ->where('status', '<>', 1)
    ->groupBy('status')
    ->get()
    ->first();
上一篇 Laravel 5 常用命令及性能优化
下一篇 Laravel 中的 UploadedFile 和 File
目录
文章列表
1 使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
使用Spring Cloud Sleuth和Zipkin进行分布式链路跟踪
2
Android 8.0 BroadcastReceiver静态注册大部分取消,动态注册,有序广播
Android 8.0 BroadcastReceiver静态注册大部分取消,动态注册,有序广播
3
Spring Boot 基于DeferredResult的异步服务
Spring Boot 基于DeferredResult的异步服务
4
CentOS下安装Maven
CentOS下安装Maven
5
PHP实现图片等比例缩略图
PHP实现图片等比例缩略图
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。