讨论数量:
DB::table('***') ->selectRaw("status,count('id') as count") ->groupBy('status') ->pluck('count', 'status')->toArray();
可以使用 mysql 的 case then
User::query()
->selectRaw("
sum(case when status = 1 then 1 end) as status_1_total,
sum(case when status = 2 then 1 end) as status_2_total,
")
// ...
select count(if(status=0,1,null)) status_0_num,count(if(status=1,1,null)) status_1_num,count(if(status=2,1,null)) status_2_num from users
你先查询10条出来,然后把查询放到子查询里面 from 条件,具体这里使用: $this->query = DB::table(DB::raw("({$this->query->toSql()}) as cashier_order")) ->selectRaw(' xxxxx ->mergeBindings($this->query);
推荐文章: