简体   繁体   中英

How to count the rows by created date in Laravel query builder?

I am trying to count the rows by created_at like

 Created_at COUNT(*) ----------------------------------- ---------- 2017-08-13 5 2017-08-12 6 2017-08-11 7 2017-07-10 8 2017-07-19 1

So i can show the client like in 2017-07-10 , there are 8 people sign up.In 2017-08-13 ,there are 5 people sign up or something like that. Here is my tried,

$count=DB::table('jobseekers')->select('created_at')->groupBy('created_at')->count();
    // return $count;
    dd($count);

But this is just showing only the number.Please guide me,thanks in advanced.

You could try something like this:

$count = DB::table('jobseekers')
             ->select('created_at', DB::raw('count(*) as peoples'))
             ->groupBy('created_at')
             ->get();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM