如何查询laravel中的选择计数?

时间:2017-05-09 03:13:35

标签: mysql laravel query-builder laravel-query-builder

我使用Query Builder机器laravel进行问题查询

我有疑问:

select count(username) as jumlah
from (select * 
from radcheck 
group by username
order by username)as counts;

我如何在laravel中创建查询构建器?

我尝试这样做,但与radcheck中的count select *相同。

  $posts = DB::table('radcheck')->select(DB::raw('count(username) as jumlah'))
            ->whereExists(function ($query) {
                $query->select('*')
                      ->from('radcheck')
                      ->groupBy('username');
            })
            ->get();
            $data= '';
      foreach ($posts as $post) {
        $data = $post->jumlah;
      }

“查询”构建器如何从查询中拉出

select count(username) as jumlah
    from (select * 
    from radcheck 
    group by username
    order by username)as counts;

0 个答案:

没有答案