CREATE TABLE a
(
d Date,
os String
)
ENGINE = MergeTree
PARTITION BY d
ORDER BY d
insert into a select '2000-01-01', ['aa','bb','cc','dd'][number % 4 + 1] from numbers(100000000)
insert into a select '2000-01-02', ['aa','bb','cc','dd'][number % 4 + 1] from numbers(100000000)
insert into a select '2000-01-03', ['aa','bb','cc','dd'][number % 4 + 1] from numbers(100000000)
insert into a select '2000-01-04', ['aa','bb','cc','dd'][number % 4 + 1] from numbers(100000000)
OPTIMIZE TABLE a FINAL
select d, count() from a group by d
select os, count() from a group by os
select d, os, count() from a group by d, os
drop table if exists a