ClickHouse/tests/queries/0_stateless/03259_grouping_sets_aliases.sql
2024-11-14 15:17:04 +00:00

10 lines
456 B
SQL

DROP TABLE IF EXISTS users;
CREATE TABLE users (name String, score UInt8, user_level String ALIAS multiIf(score <= 3, 'LOW', score <= 6, 'MEDIUM', 'HIGH') ) ENGINE=MergeTree ORDER BY name;
INSERT INTO users VALUES ('a',1),('b',2),('c', 50);
SELECT user_level as level_alias, uniq(name) as name_alias, grouping(level_alias) as _totals
FROM remote('127.0.0.{1,2}', currentDatabase(), users)
GROUP BY GROUPING SETS ((level_alias))
ORDER BY name_alias DESC;