Created
July 7, 2023 12:11
-
-
Save jamesmills/91f3056dc1a9f39ed10273497a7fe8a5 to your computer and use it in GitHub Desktop.
Fill Gaps in Statistical Time Series - Date by the hour
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$requests = DB::table('advert_requests as ar') | |
->select(DB::raw("date_format(ar.created_at, '%Y-%m-%d %H' ) AS grouped_hour, count(*) AS requests")) | |
->join('placements as p', 'p.id', '=', 'ar.placement_id') | |
->where('ar.created_at', '>=', $from) | |
->where('p.site_id', $site_id) | |
->groupBy('grouped_hour') | |
->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't build the SQL query like this because the
WITH ...
needs to proceed everything. staudenmeier/laravel-cte is good. I've implemented CTEs in my PG driver the same way like he did.We can do a session again some time. Send me a DM on Twitter if you want to.