OFFSET 句

適用対象:check marked yes Databricks SQL 「はい」のチェックマーク Databricks Runtime 11.3 LTS 以降

ステートメントまたはサブクエリによって返される行の数をスキップします。 この句は主に、LIMIT と組み合わせて使用して結果セットをページング し、ORDER BY と組み合わせて使用して決定論的な結果を生成します。

注意

LIMITOFFSET を使用して結果セットをページングしても、スキップされた行は処理されます。 これらの行は結果セットに表示されないだけです。 この手法を使用した改ページ位置の自動修正は、リソースを集中的に使用するクエリではお勧めできません。

構文

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