Created
September 5, 2017 00:14
-
-
Save alexey-milovidov/2f2739347818013216139548ec989b20 to your computer and use it in GitHub Desktop.
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
| :) CREATE TABLE test.sessions (begin DateTime, end DateTime) ENGINE = Memory | |
| CREATE TABLE test.sessions | |
| ( | |
| begin DateTime, | |
| end DateTime | |
| ) ENGINE = Memory | |
| Ok. | |
| 0 rows in set. Elapsed: 0.009 sec. | |
| :) INSERT INTO test.sessions VALUES ('2017-09-01 01:02:03', '2017-09-01 01:03:03'), ('2017-09-01 01:02:33', '2017-09-01 01:03:33') | |
| INSERT INTO test.sessions VALUES | |
| Ok. | |
| 2 rows in set. Elapsed: 0.015 sec. | |
| :) SELECT begin + arrayJoin(range(toUInt64(end - begin))) AS time, count() AS num_concurrent_sessions FROM test.sessions GROUP BY time ORDER BY time | |
| SELECT | |
| begin + arrayJoin(range(toUInt64(end - begin))) AS time, | |
| count() AS num_concurrent_sessions | |
| FROM test.sessions | |
| GROUP BY time | |
| ORDER BY time ASC | |
| ┌────────────────time─┬─num_concurrent_sessions─┐ | |
| │ 2017-09-01 01:02:03 │ 1 │ | |
| │ 2017-09-01 01:02:04 │ 1 │ | |
| │ 2017-09-01 01:02:05 │ 1 │ | |
| │ 2017-09-01 01:02:06 │ 1 │ | |
| │ 2017-09-01 01:02:07 │ 1 │ | |
| │ 2017-09-01 01:02:08 │ 1 │ | |
| │ 2017-09-01 01:02:09 │ 1 │ | |
| │ 2017-09-01 01:02:10 │ 1 │ | |
| │ 2017-09-01 01:02:11 │ 1 │ | |
| │ 2017-09-01 01:02:12 │ 1 │ | |
| │ 2017-09-01 01:02:13 │ 1 │ | |
| │ 2017-09-01 01:02:14 │ 1 │ | |
| │ 2017-09-01 01:02:15 │ 1 │ | |
| │ 2017-09-01 01:02:16 │ 1 │ | |
| │ 2017-09-01 01:02:17 │ 1 │ | |
| │ 2017-09-01 01:02:18 │ 1 │ | |
| │ 2017-09-01 01:02:19 │ 1 │ | |
| │ 2017-09-01 01:02:20 │ 1 │ | |
| │ 2017-09-01 01:02:21 │ 1 │ | |
| │ 2017-09-01 01:02:22 │ 1 │ | |
| │ 2017-09-01 01:02:23 │ 1 │ | |
| │ 2017-09-01 01:02:24 │ 1 │ | |
| │ 2017-09-01 01:02:25 │ 1 │ | |
| │ 2017-09-01 01:02:26 │ 1 │ | |
| │ 2017-09-01 01:02:27 │ 1 │ | |
| │ 2017-09-01 01:02:28 │ 1 │ | |
| │ 2017-09-01 01:02:29 │ 1 │ | |
| │ 2017-09-01 01:02:30 │ 1 │ | |
| │ 2017-09-01 01:02:31 │ 1 │ | |
| │ 2017-09-01 01:02:32 │ 1 │ | |
| │ 2017-09-01 01:02:33 │ 2 │ | |
| │ 2017-09-01 01:02:34 │ 2 │ | |
| │ 2017-09-01 01:02:35 │ 2 │ | |
| │ 2017-09-01 01:02:36 │ 2 │ | |
| │ 2017-09-01 01:02:37 │ 2 │ | |
| │ 2017-09-01 01:02:38 │ 2 │ | |
| │ 2017-09-01 01:02:39 │ 2 │ | |
| │ 2017-09-01 01:02:40 │ 2 │ | |
| │ 2017-09-01 01:02:41 │ 2 │ | |
| │ 2017-09-01 01:02:42 │ 2 │ | |
| │ 2017-09-01 01:02:43 │ 2 │ | |
| │ 2017-09-01 01:02:44 │ 2 │ | |
| │ 2017-09-01 01:02:45 │ 2 │ | |
| │ 2017-09-01 01:02:46 │ 2 │ | |
| │ 2017-09-01 01:02:47 │ 2 │ | |
| │ 2017-09-01 01:02:48 │ 2 │ | |
| │ 2017-09-01 01:02:49 │ 2 │ | |
| │ 2017-09-01 01:02:50 │ 2 │ | |
| │ 2017-09-01 01:02:51 │ 2 │ | |
| │ 2017-09-01 01:02:52 │ 2 │ | |
| │ 2017-09-01 01:02:53 │ 2 │ | |
| │ 2017-09-01 01:02:54 │ 2 │ | |
| │ 2017-09-01 01:02:55 │ 2 │ | |
| │ 2017-09-01 01:02:56 │ 2 │ | |
| │ 2017-09-01 01:02:57 │ 2 │ | |
| │ 2017-09-01 01:02:58 │ 2 │ | |
| │ 2017-09-01 01:02:59 │ 2 │ | |
| │ 2017-09-01 01:03:00 │ 2 │ | |
| │ 2017-09-01 01:03:01 │ 2 │ | |
| │ 2017-09-01 01:03:02 │ 2 │ | |
| │ 2017-09-01 01:03:03 │ 1 │ | |
| │ 2017-09-01 01:03:04 │ 1 │ | |
| │ 2017-09-01 01:03:05 │ 1 │ | |
| │ 2017-09-01 01:03:06 │ 1 │ | |
| │ 2017-09-01 01:03:07 │ 1 │ | |
| │ 2017-09-01 01:03:08 │ 1 │ | |
| │ 2017-09-01 01:03:09 │ 1 │ | |
| │ 2017-09-01 01:03:10 │ 1 │ | |
| │ 2017-09-01 01:03:11 │ 1 │ | |
| │ 2017-09-01 01:03:12 │ 1 │ | |
| │ 2017-09-01 01:03:13 │ 1 │ | |
| │ 2017-09-01 01:03:14 │ 1 │ | |
| │ 2017-09-01 01:03:15 │ 1 │ | |
| │ 2017-09-01 01:03:16 │ 1 │ | |
| │ 2017-09-01 01:03:17 │ 1 │ | |
| │ 2017-09-01 01:03:18 │ 1 │ | |
| │ 2017-09-01 01:03:19 │ 1 │ | |
| │ 2017-09-01 01:03:20 │ 1 │ | |
| │ 2017-09-01 01:03:21 │ 1 │ | |
| │ 2017-09-01 01:03:22 │ 1 │ | |
| │ 2017-09-01 01:03:23 │ 1 │ | |
| │ 2017-09-01 01:03:24 │ 1 │ | |
| │ 2017-09-01 01:03:25 │ 1 │ | |
| │ 2017-09-01 01:03:26 │ 1 │ | |
| │ 2017-09-01 01:03:27 │ 1 │ | |
| │ 2017-09-01 01:03:28 │ 1 │ | |
| │ 2017-09-01 01:03:29 │ 1 │ | |
| │ 2017-09-01 01:03:30 │ 1 │ | |
| │ 2017-09-01 01:03:31 │ 1 │ | |
| │ 2017-09-01 01:03:32 │ 1 │ | |
| └─────────────────────┴─────────────────────────┘ | |
| 90 rows in set. Elapsed: 0.014 sec. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
help please to replace this arrayJoin with timeSlots