How to count and retrieve data for different periods in one query?


#1

I want to count and retrieve data for different periods like today, total, this week, etc.

How to count for example this_week?

Here is starting code:

public function findTotalRegistered(Query $query, Array $options)
  {
    $total = $query->func()->count('id');

    $query
      ->select([
        'total' => $total,
        //'today' => $today,
        //'this_week' => $this_week,
        //'this_month' => $this_month,
        //'this_year' => $this_year
      ]);

    return $query;
  }

#2

For mysql something like this?

$query->where(["WEEK(created) = WEEK(NOW())"]);

#3

Yes, I have created seperate queries like that for all needed periods, but unable to use it as subqueries.