Skip to content

Instantly share code, notes, and snippets.

@ismasan
Created July 27, 2010 13:31
Show Gist options
  • Save ismasan/492223 to your computer and use it in GitHub Desktop.
Save ismasan/492223 to your computer and use it in GitHub Desktop.
SELECT app_id, AVG(logs.hits) AS hits_avg, SUM(logs.hits) AS hits,
CONCAT(YEAR(logs.created_at), '-', LPAD(MONTH(logs.created_at), 2, '0'), '-', LPAD(DAY(logs.created_at), 2, '0'), ' ', LPAD(HOUR(logs.created_at), 2, '0'),':',LPAD(FLOOR(MINUTE(logs.created_at)/5)*5, 2, '0'), ':00') AS date_interval
FROM `logs`
WHERE logs.created_at > "2010-07-22 00:00:00"
GROUP BY app_id, date_interval
ORDER BY app_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment