2022-03-01 11:35:17 +00:00
|
|
|
set group_by_two_level_threshold = 100000;
|
2021-08-10 13:57:37 +00:00
|
|
|
set enable_positional_arguments = 1;
|
|
|
|
|
2021-08-09 14:16:44 +00:00
|
|
|
drop table if exists test;
|
2021-10-20 07:45:19 +00:00
|
|
|
drop table if exists test2;
|
|
|
|
|
2021-08-19 15:18:39 +00:00
|
|
|
create table test(x1 Int, x2 Int, x3 Int) engine=Memory();
|
|
|
|
insert into test values (1, 10, 100), (10, 1, 10), (100, 100, 1);
|
2021-08-10 13:57:37 +00:00
|
|
|
|
2021-08-19 15:18:39 +00:00
|
|
|
-- { echo }
|
|
|
|
select x3, x2, x1 from test order by 1;
|
|
|
|
select x3, x2, x1 from test order by x3;
|
2021-08-10 13:57:37 +00:00
|
|
|
|
2021-08-19 15:18:39 +00:00
|
|
|
select x3, x2, x1 from test order by 1 desc;
|
|
|
|
select x3, x2, x1 from test order by x3 desc;
|
2021-08-10 13:57:37 +00:00
|
|
|
|
2022-02-02 19:50:33 +00:00
|
|
|
insert into test values (1, 10, 100), (10, 1, 10), (100, 100, 1);
|
2021-08-19 15:18:39 +00:00
|
|
|
select x3, x2 from test group by x3, x2;
|
|
|
|
select x3, x2 from test group by 1, 2;
|
2021-08-09 14:16:44 +00:00
|
|
|
|
2021-08-19 15:18:39 +00:00
|
|
|
select x1, x2, x3 from test order by x3 limit 1 by x3;
|
|
|
|
select x1, x2, x3 from test order by 3 limit 1 by 3;
|
|
|
|
select x1, x2, x3 from test order by x3 limit 1 by x1;
|
|
|
|
select x1, x2, x3 from test order by 3 limit 1 by 1;
|
2021-08-09 14:16:44 +00:00
|
|
|
|
2021-10-20 07:49:05 +00:00
|
|
|
explain syntax select x3, x2, x1 from test order by 1;
|
|
|
|
explain syntax select x3 + 1, x2, x1 from test order by 1;
|
|
|
|
explain syntax select x3, x3 - x2, x2, x1 from test order by 2;
|
|
|
|
explain syntax select x3, if(x3 > 10, x3, plus(x1, x2)), x1 + x2 from test order by 2;
|
|
|
|
explain syntax select max(x1), x2 from test group by 2 order by 1, 2;
|
2021-10-22 12:22:16 +00:00
|
|
|
explain syntax select 1 + greatest(x1, 1), x2 from test group by 1, 2;
|
2021-10-20 07:49:05 +00:00
|
|
|
|
2021-10-20 07:45:19 +00:00
|
|
|
select max(x1), x2 from test group by 1, 2; -- { serverError 43 }
|
2021-10-22 12:22:16 +00:00
|
|
|
select 1 + max(x1), x2 from test group by 1, 2; -- { serverError 43 }
|
2021-10-20 07:45:19 +00:00
|
|
|
|
|
|
|
explain syntax select x1 + x3, x3 from test group by 1, 2;
|
|
|
|
|
|
|
|
create table test2(x1 Int, x2 Int, x3 Int) engine=Memory;
|
|
|
|
insert into test2 values (1, 10, 100), (10, 1, 10), (100, 100, 1);
|
|
|
|
select x1, x1 * 2, max(x2), max(x3) from test2 group by 2, 1, x1 order by 1, 2, 4 desc, 3 asc;
|
2021-11-15 12:09:04 +00:00
|
|
|
|
2021-11-24 20:54:49 +00:00
|
|
|
select a, b, c, d, e, f from (select 44 a, 88 b, 13 c, 14 d, 15 e, 16 f) t group by 1,2,3,4,5,6;
|
|
|
|
|
|
|
|
explain syntax select plus(1, 1) as a group by a;
|
|
|
|
select substr('aaaaaaaaaaaaaa', 8) as a group by a;
|
2021-12-20 05:43:07 +00:00
|
|
|
select substr('aaaaaaaaaaaaaa', 8) as a group by substr('aaaaaaaaaaaaaa', 8);
|
|
|
|
|
2022-03-25 13:33:54 +00:00
|
|
|
select b from (select 5 as a, 'Hello' as b order by a);
|
|
|
|
select b from (select 5 as a, 'Hello' as b group by a);
|
2022-03-25 19:03:12 +00:00
|
|
|
select b from (select 5 as a, 'Hello' as b order by 1);
|
2022-07-16 20:23:49 +00:00
|
|
|
|
|
|
|
create table tp2(first_col String, second_col Int32) engine = MergeTree() order by tuple();
|
|
|
|
select count(*) from (select first_col, count(second_col) from tp2 group by 1);
|
|
|
|
select total from (select first_col, count(second_col) as total from tp2 group by 1);
|