Skip to content

Instantly share code, notes, and snippets.

@yukihirai0505
Created December 11, 2015 12:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yukihirai0505/a8c1e31ec1d453e868d4 to your computer and use it in GitHub Desktop.
Save yukihirai0505/a8c1e31ec1d453e868d4 to your computer and use it in GitHub Desktop.
SET @t = 2;
SELECT
SUM(A.counter) AS counter
FROM
(SELECT
FROM_UNIXTIME(CEILING(UNIX_TIMESTAMP(access_date) / (@t * 60)) * (@t * 60)) AS access_date,
1 AS counter
FROM
tmp_user
GROUP BY CEILING(UNIX_TIMESTAMP(access_date) / (@t * 60)) * (@t * 60)) A
GROUP BY DATE_FORMAT(A.access_date, '%Y%m%d');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment