Created
June 20, 2016 21:00
-
-
Save alexey-milovidov/2dee968eb95df63b271208f89d3697c3 to your computer and use it in GitHub Desktop.
Example of rounding time to 5-second interval in ClickHouse.
This file contains hidden or 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 toDateTime(intDiv(toUInt32(EventTime), 5) * 5) AS k, count(), uniq(UserID) FROM hits_layer WHERE CounterID = 29761725 AND EventDate = today() AND EventTime >= now() - 600 GROUP BY k ORDER BY k | |
SELECT | |
toDateTime(intDiv(toUInt32(EventTime), 5) * 5) AS k, | |
count(), | |
uniq(UserID) | |
FROM hits_layer | |
WHERE (CounterID = 29761725) AND (EventDate = today()) AND (EventTime >= (now() - 600)) | |
GROUP BY k | |
ORDER BY k ASC | |
┌───────────────────k─┬─count()─┬─uniq(UserID)─┐ | |
│ 2016-06-20 23:49:55 │ 1 │ 1 │ | |
│ 2016-06-20 23:50:00 │ 1 │ 1 │ | |
│ 2016-06-20 23:50:05 │ 1 │ 1 │ | |
│ 2016-06-20 23:50:10 │ 1 │ 1 │ | |
│ 2016-06-20 23:50:25 │ 3 │ 1 │ | |
│ 2016-06-20 23:50:45 │ 1 │ 1 │ | |
│ 2016-06-20 23:50:50 │ 1 │ 1 │ | |
│ 2016-06-20 23:51:00 │ 1 │ 1 │ | |
│ 2016-06-20 23:51:05 │ 2 │ 1 │ | |
│ 2016-06-20 23:51:25 │ 1 │ 1 │ | |
│ 2016-06-20 23:51:30 │ 1 │ 1 │ | |
│ 2016-06-20 23:51:40 │ 1 │ 1 │ | |
│ 2016-06-20 23:51:55 │ 1 │ 1 │ | |
│ 2016-06-20 23:52:05 │ 2 │ 2 │ | |
│ 2016-06-20 23:52:15 │ 1 │ 1 │ | |
│ 2016-06-20 23:52:30 │ 1 │ 1 │ | |
│ 2016-06-20 23:53:20 │ 1 │ 1 │ | |
│ 2016-06-20 23:53:35 │ 1 │ 1 │ | |
│ 2016-06-20 23:54:05 │ 1 │ 1 │ | |
│ 2016-06-20 23:54:20 │ 1 │ 1 │ | |
│ 2016-06-20 23:56:00 │ 1 │ 1 │ | |
│ 2016-06-20 23:56:05 │ 3 │ 1 │ | |
│ 2016-06-20 23:56:45 │ 2 │ 2 │ | |
│ 2016-06-20 23:57:00 │ 1 │ 1 │ | |
│ 2016-06-20 23:57:15 │ 1 │ 1 │ | |
│ 2016-06-20 23:57:20 │ 1 │ 1 │ | |
│ 2016-06-20 23:57:25 │ 1 │ 1 │ | |
└─────────────────────┴─────────┴──────────────┘ | |
27 rows in set. Elapsed: 0.053 sec. Processed 352.26 thousand rows, 6.34 MB (6.70 million rows/s., 120.55 MB/s.) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment