LIMIT yan tümcesi

Şunun için geçerlidir:evet olarak işaretlendi Databricks SQL denetimi yes Databricks Runtime olarak işaretlendi

Sorgu tarafından döndürülen satır sayısını kısıtlar. Genel olarak bu yan tümce, sonuçların belirlenimci olduğundan emin olmak için ORDER BY ile birlikte kullanılır.

Sözdizimi

LIMIT { ALL | integer_expression }

Parametre

  • TÜM

    Belirtilirse, sorgu tüm satırları döndürür. Başka bir deyişle, bu seçenek belirtilirse hiçbir sınır uygulanmaz.

  • integer_expression

    Tamsayı döndüren değişmez değer ifadesi.

Örnekler

> CREATE TEMP VIEW person (name, age)
    AS VALUES ('Zen Hui', 25),
              ('Anil B' , 18),
              ('Shone S', 16),
              ('Mike A' , 25),
              ('John A' , 18),
              ('Jack N' , 16);

-- Select the first two rows.
> SELECT name, age FROM person ORDER BY name LIMIT 2;
 Anil B  18
 Jack N  16

-- Select the 4th and 5th rows by alphabetical order.
> SELECT name, age FROM person ORDER BY name LIMIT 2 OFFSET 3;
  Mike A  25
 Shone S  16

-- Specifying ALL option on LIMIT returns all the rows.
> SELECT name, age FROM person ORDER BY name LIMIT ALL;
  Anil B  18
  Jack N  16
  John A  18
  Mike A  25
 Shone S  16
 Zen Hui  25

-- A function expression as an input to LIMIT.
> SELECT name, age FROM person ORDER BY name LIMIT length('SPARK');
  Anil B  18
  Jack N  16
  John A  18
  Mike A  25
 Shone S  16

-- A non-literal expression as an input to LIMIT is not allowed.
SELECT name, age FROM person ORDER BY name LIMIT length(name);
Error: The limit expression must evaluate to a constant value