clausola OFFSET
Si applica a: Databricks SQL
Databricks Runtime 11.3 LTS e versioni successive
Ignora una serie di righe restituite da un'istruzione o da una sottoquery.
Questa clausola viene usata principalmente in combinazione con LIMIT per pagina tramite un set di risultati e ORDER BY
per produrre un risultato deterministico.
Nota
Quando si esegue il paging in un set di risultati usando LIMIT
e OFFSET
, le righe ignorate vengono comunque elaborate.
Queste righe vengono semplicemente eliminate dal set di risultati.
L'impaginazione con questa tecnica non è consigliata per le query a elevato utilizzo di risorse.
Sintassi
OFFSET integer_expression
Parametri
integer_expression
Espressione letterale positiva che restituisce un numero intero.
Esempi
> 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 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 and an OFFSET of zero, returns all the rows.
> SELECT name, age FROM person ORDER BY name LIMIT ALL OFFSET 0;
Anil B 18
Jack N 16
John A 18
Mike A 25
Shone S 16
Zen Hui 25
-- A constant function expression as an input to OFFSET.
> SELECT name, age FROM person ORDER BY name OFFSET length('SPARK');
Zen Hui 25
-- A non-literal expression as an input to OFFSET is not allowed.
> SELECT name, age FROM person ORDER BY name OFFSET length(name);
Error: The offset expression must evaluate to a constant value