Last active
August 29, 2015 14:18
-
-
Save codenamegary/547f4364201771ce2227 to your computer and use it in GitHub Desktop.
Stats Refactoring
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
SELECT | |
apps.id as `id`, | |
apps.name as `name`, | |
sum(stats_today.views) as `viewsToday`, | |
sum(stats_total.views) as `viewsTotal`, | |
sum(stats_total.loads) as `loadsTotal` | |
FROM | |
apps | |
LEFT JOIN widgets | |
ON widgets.app_id = apps.id | |
LEFT JOIN stats as stats_today | |
ON stats.widget_id = widgets.id | |
AND stats.date = date(now()) | |
LEFT JOIN stats as stats_total | |
ON stats.widget_id = widgets.id | |
GROUP BY | |
apps.id | |
LIMIT perPage | |
OFFSET ( ( page - 1 ) * perPage ) |
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
private function getAppInformation() | |
{ | |
$sql = file_get_contents('stats-query.sql'); | |
$data = DB::select($sql); | |
$apps = App::hydrate($data); | |
return $apps; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment