2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS limit_by;
|
|
|
|
CREATE TABLE limit_by (Num UInt32, Name String) ENGINE = Memory;
|
|
|
|
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (1, 'John');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (1, 'John');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (3, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (3, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (3, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (4, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (4, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (5, 'Bill');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (7, 'Bill');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (7, 'Bill');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (7, 'Mary');
|
|
|
|
INSERT INTO limit_by (Num, Name) VALUES (7, 'John');
|
2016-12-30 12:57:09 +00:00
|
|
|
|
|
|
|
-- Two elemens in each group
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT Num FROM limit_by ORDER BY Num LIMIT 2 BY Num;
|
2016-12-30 12:57:09 +00:00
|
|
|
|
|
|
|
-- LIMIT BY doesn't affect result of GROUP BY
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT Num, count(*) FROM limit_by GROUP BY Num ORDER BY Num LIMIT 2 BY Num;
|
2016-12-30 12:57:09 +00:00
|
|
|
|
|
|
|
-- LIMIT BY can be combined with LIMIT
|
2019-04-16 14:13:13 +00:00
|
|
|
SELECT Num, Name FROM limit_by ORDER BY Num LIMIT 1 BY Num, Name LIMIT 3;
|
2016-12-30 12:57:09 +00:00
|
|
|
|
2017-01-09 13:24:54 +00:00
|
|
|
-- Distributed LIMIT BY
|
2018-01-29 10:01:18 +00:00
|
|
|
SELECT dummy FROM remote('127.0.0.{2,3}', system.one) LIMIT 1 BY dummy;
|
|
|
|
SELECT dummy FROM remote('127.0.0.{2,3}', system.one) LIMIT 2 BY dummy;
|
2017-01-09 13:24:54 +00:00
|
|
|
|
2018-01-29 10:01:18 +00:00
|
|
|
SELECT 1 as one FROM remote('127.0.0.{2,3}', system.one) LIMIT 1 BY one;
|
2017-01-09 13:24:54 +00:00
|
|
|
|
2019-03-15 15:22:22 +00:00
|
|
|
-- Distributed LIMIT BY with LIMIT
|
|
|
|
SELECT toInt8(number / 5 + 100) AS x FROM remote('127.0.0.1', system.numbers) LIMIT 2 BY x LIMIT 5;
|
|
|
|
|
2019-05-23 16:25:53 +00:00
|
|
|
-- Distributed LIMIT BY with ORDER BY non-selected column
|
|
|
|
SELECT 1 AS x FROM remote('127.0.0.{2,3}', system.one) ORDER BY dummy LIMIT 1 BY x;
|
|
|
|
|
2019-04-16 14:13:13 +00:00
|
|
|
DROP TABLE IF EXISTS limit_by;
|