Answers for "How to do a cumulative count using Raw SQl / Laravel - Eloquent ORM"

SQL
0

How to do a cumulative count using Raw SQl / Laravel - Eloquent ORM

#If your mysql version support window function, you can try to use SUM window function to do cumulative count

DB::table(DB::raw('(select COUNT(*) created_users_to_this_date, DATE_FORMAT(created_at, \'%Y-%m\') date 
    from `users` 
    where `users`.`deleted_at` is null 
    group by `date`) t1'))
->select('created_users_to_this_date','date',DB::raw('SUM(created_users_to_this_date) OVER(ORDER BY date) total_users_created_to_date'))
->get();
Posted by: Guest on May-08-2022

Code answers related to "SQL"

Browse Popular Code Answers by Language