Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE checkins
- (
- date_in DateTime,
- date_out DateTime,
- age Int32,
- sex String,
- date_day Date MATERIALIZED toDate(date_in)
- ) ENGINE = MergeTree(date_day, date_in, 8192)
- INSERT INTO checkins VALUES
- (toDateTime('2018-01-01 08:30:00'), toDateTime('2018-01-01 16:30:00'), 32, 'M'),
- (toDateTime('2018-01-01 09:30:00'), toDateTime('2018-01-01 10:30:00'), 28, 'M'),
- (toDateTime('2018-01-01 10:15:00'), toDateTime('2018-01-01 10:45:00'), 30, 'M'),
- (toDateTime('2018-01-01 11:30:00'), toDateTime('2018-01-01 11:45:00'), 35, 'M'),
- (toDateTime('2018-01-01 14:30:00'), toDateTime('2018-01-01 17:30:00'), 25, 'F');
- SELECT count(*), instant
- FROM
- (
- SELECT arrayJoin([toDateTime('2018-01-01 10:00:00'), toDateTime('2018-01-01 12:00:00'), toDateTime('2018-01-01 14:00:00'), toDateTime('2018-01-01 16:00:00')] AS tabinstants) AS instant
- FROM checkins
- WHERE (date_in < instant) AND (date_out > instant)
- )
- GROUP BY instant
- ORDER BY instant ASC
- ┌─count()─┬─────────────instant─┐
- │ 2 │ 2018-01-01 10:00:00 │
- │ 1 │ 2018-01-01 12:00:00 │
- │ 1 │ 2018-01-01 14:00:00 │
- │ 2 │ 2018-01-01 16:00:00 │
- └─────────┴─────────────────────┘
- ┌─count()─┬─────────────instant─┐
- │ 3 │ 2018-01-01 10:00:00 │
- │ 1 │ 2018-01-01 12:00:00 │
- │ 2 │ 2018-01-01 14:00:00 │
- │ 2 │ 2018-01-01 16:00:00 │
- └─────────┴─────────────────────┘
Add Comment
Please, Sign In to add comment