OFFSET 子句
適用於: Databricks SQL Databricks Runtime 11.3 LTS 和更新版本
略過語句或子查詢所傳回的數據列數目。
這個子句主要用於搭配 LIMIT 逐 頁查看 結果集,並 ORDER BY
產生決定性結果。
注意
使用 和 OFFSET
略過的數據列分頁時,仍會處理結果集LIMIT
。
這些數據列只會從結果集隱藏。
不建議針對需要大量資源的查詢使用這項技術分頁。
語法
OFFSET integer_expression
參數
integer_expression
傳回整數的正常值表達式。
範例
> 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