ClickHouse/dbms/tests/queries/0_stateless/00409_shard_limit_by.sql

33 lines
1.4 KiB
MySQL
Raw Normal View History

2016-12-30 12:57:09 +00:00
DROP TABLE IF EXISTS test.limit_by;
CREATE TABLE test.limit_by (Num UInt32, Name String) ENGINE = Memory;
INSERT INTO test.limit_by (Num, Name) VALUES (1, 'John');
INSERT INTO test.limit_by (Num, Name) VALUES (1, 'John');
INSERT INTO test.limit_by (Num, Name) VALUES (3, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (3, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (3, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (4, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (4, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (5, 'Bill');
INSERT INTO test.limit_by (Num, Name) VALUES (7, 'Bill');
INSERT INTO test.limit_by (Num, Name) VALUES (7, 'Bill');
INSERT INTO test.limit_by (Num, Name) VALUES (7, 'Mary');
INSERT INTO test.limit_by (Num, Name) VALUES (7, 'John');
-- Two elemens in each group
SELECT Num FROM test.limit_by ORDER BY Num LIMIT 2 BY Num;
-- LIMIT BY doesn't affect result of GROUP BY
SELECT Num, count(*) FROM test.limit_by GROUP BY Num ORDER BY Num LIMIT 2 BY Num;
-- LIMIT BY can be combined with LIMIT
SELECT Num, Name FROM test.limit_by ORDER BY Num LIMIT 1 BY Num, Name LIMIT 3;
-- Distributed LIMIT BY
2017-01-25 13:21:35 +00:00
SELECT dummy FROM remote('127.0.0.{1,2}', system.one) LIMIT 1 BY dummy;
SELECT dummy FROM remote('127.0.0.{1,2}', system.one) LIMIT 2 BY dummy;
2017-01-25 13:21:35 +00:00
SELECT 1 as one FROM remote('127.0.0.{1,2}', system.one) LIMIT 1 BY one;
2016-12-30 12:57:09 +00:00
DROP TABLE IF EXISTS test.limit_by;