SELECTSELECT
1つ以上のテーブルから結果セットを取得します。Retrieves result sets from one or more tables.
構文Syntax
[ WITH with_query [ , ... ] ]
select_statement [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select_statement, ... ]
[ ORDER BY { expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [ , ... ] } ]
[ SORT BY { expression [ ASC | DESC ] [ NULLS { FIRST | LAST } ] [ , ... ] } ]
[ CLUSTER BY { expression [ , ... ] } ]
[ DISTRIBUTE BY { expression [, ... ] } ]
[ WINDOW { named_window [ , WINDOW named_window, ... ] } ]
[ LIMIT { ALL | expression } ]
select_statement
がとして定義されている場合While select_statement
is defined as
SELECT [ hints , ... ] [ ALL | DISTINCT ] { named_expression [ , ... ] }
FROM { from_item [ , ... ] }
[ PIVOT clause ]
[ LATERAL VIEW clause ] [ ... ]
[ WHERE boolean_expression ]
[ GROUP BY expression [ , ... ] ]
[ HAVING boolean_expression ]
パラメーターParameters
with_querywith_query
メインクエリブロックの前にある1つ以上の 共通テーブル式 。これらのテーブル式は、後で句で参照でき
FROM
ます。One or more common table expressions before the main query block.These table expressions can be referenced later in theFROM
clause. 句内の繰り返しサブクエリブロックを抽象化FROM
して、クエリの読みやすさを向上させるには、この方法が役立ちます。This is useful to abstract out repeated subquery blocks in theFROM
clause and improves readability of the query.-
ヒントを使用すると、Spark オプティマイザーが計画上の決定をより適切に行うことができます。Hints help the Spark optimizer make better planning decisions. Spark は、結合戦略の選択とデータの再分割に影響するヒントをサポートしています。Spark supports hints that influence selection of join strategies and repartitioning of the data.
ALLALL
リレーションシップの一致するすべての行を選択します。Select all matching rows from the relation. 既定で有効です。Enabled by default.
DISTINCTDISTINCT
結果内の重複部分を削除した後、リレーションシップからすべての一致する行を選択します。Select all matching rows from the relation after removing duplicates in results.
named_expressionnamed_expression
割り当てられた名前を持つ式。An expression with an assigned name. 列の式を表します。Denotes a column expression.
構文:
expression [AS] [alias]
Syntax:expression [AS] [alias]
from_itemfrom_item
クエリの入力のソース。A source of input for the query. 次のいずれか:One of the following:
- テーブル識別子Table identifier
[database_name.] table_name
: テーブル名。必要に応じて、データベース名で修飾します。[database_name.] table_name
: A table name, optionally qualified with a database name.delta.`<path-to-table>`
: 既存のデルタテーブルの場所。delta.`<path-to-table>`
: The location of an existing Delta table.TIMESTAMP AS OF
テーブルリレーションの後に、、または構文を使用して、タイムトラベルバージョンを指定できVERSION AS OF
@
ます。You can specify a time travel version usingTIMESTAMP AS OF
,VERSION AS OF
, or@
syntax after a table relation. 詳細については 、「テーブルの古いスナップショットのクエリ (タイムトラベル) 」を参照してください。See Query an older snapshot of a table (time travel) for details.
- JOINJOIN
- テーブル値関数 (TVF)Table-valued function (TVF)
- インライン テーブルInline table
- サブクエリSubquery
- テーブル識別子Table identifier
-
データのパースペクティブに使用されます。特定の列の値に基づいて集計値を取得できます。Used for data perspective; you can get the aggregated values based on specific column value.
-
などのジェネレーター関数と組み合わせて使用されます。この関数
EXPLODE
は、1つ以上の行を含む仮想テーブルを生成します。Used in conjunction with generator functions such asEXPLODE
, which generates a virtual table containing one or more rows.LATERAL VIEW
各元の出力行に行を適用します。LATERAL VIEW
applies the rows to each original output row. WHEREWHERE
指定され
FROM
た述語に基づいて句の結果をフィルター処理します。Filters the result of theFROM
clause based on the supplied predicates.-
行をグループ化するために使用される式。The expressions that are used to group the rows. これは、集計関数 (、、、、) と共に使用して、グループ
MIN
MAX
COUNT
SUM
AVG
化式と各グループの集計値に基づいて行をグループ化します。This is used in conjunction with aggregate functions (MIN
,MAX
,COUNT
,SUM
,AVG
) to group rows based on the grouping expressions and aggregate values in each group.FILTER
句が集計関数に関連付けられている場合は、一致する行だけがその関数に渡されます。When aFILTER
clause is attached to an aggregate function, only the matching rows are passed to that function. -
によって生成される行のフィルター処理に使用する述語
GROUP BY
。The predicates by which the rows produced byGROUP BY
are filtered.HAVING
句は、グループ化が実行された後に行をフィルター処理するために使用されます。TheHAVING
clause is used to filter rows after the grouping is performed. を指定せずにを指定すると、HAVING
GROUP BY
GROUP BY
グループ化式 (グローバル集計) がないことを示します。If you specifyHAVING
withoutGROUP BY
, it indicates aGROUP BY
without grouping expressions (global aggregate). -
クエリの完全な結果セットの行の順序。An ordering of the rows of the complete result set of the query. 出力行は、パーティションに対して順序付けされます。The output rows are ordered across the partitions. このパラメーターは
SORT BY
、、、およびと同時に使用CLUSTER BY
DISTRIBUTE BY
することはできません。また、一緒に指定することもできません。This parameter is mutually exclusive withSORT BY
,CLUSTER BY
, andDISTRIBUTE BY
and cannot be specified together. -
各パーティション内で行が順序付けられる順序。An ordering by which the rows are ordered within each partition. このパラメーターは、とで相互に排他的であり
ORDER BY
CLUSTER BY
、同時に指定することはできません。This parameter is mutually exclusive withORDER BY
andCLUSTER BY
and cannot be specified together. -
行の再パーティション分割と並べ替えに使用する式のセット。A set of expressions that is used to repartition and sort the rows. この句を使用すると、とを一緒に使用した場合と同じ効果があり
DISTRIBUTE BY
SORT BY
ます。Using this clause has the same effect of usingDISTRIBUTE BY
andSORT BY
together. -
結果行を再パーティション分割する式のセット。A set of expressions by which the result rows are repartitioned. このパラメーターは、とで相互に排他的であり
ORDER BY
CLUSTER BY
、同時に指定することはできません。This parameter is mutually exclusive withORDER BY
andCLUSTER BY
and cannot be specified together. -
ステートメントまたはサブクエリで返すことができる行の最大数。The maximum number of rows that can be returned by a statement or subquery. この句は、主にと組み合わせて
ORDER BY
決定的な結果を生成するために使用されます。This clause is mostly used in the conjunction withORDER BY
to produce a deterministic result. boolean_expressionboolean_expression
結果の型に評価される任意の式
Boolean
。Any expression that evaluates to a result typeBoolean
. 論理演算子 (、) を使用して、2つ以上の式を組み合わせることができAND
OR
ます。You can combine two or more expressions together using the logical operators (AND
,OR
).式 (expression)expression
値に評価される1つ以上の値、演算子、および SQL 関数の組み合わせ。A combination of one or more values, operators, and SQL functions that evaluates to a value.
named_windownamed_window
1つ以上のソースウィンドウ仕様のエイリアス。Aliases for one or more source window specifications. ソースウィンドウの指定は、クエリのウィンドウ定義で参照できます。The source window specifications can be referenced in the window definitions in the query.
関連記事Related articles
- CASE 句CASE clause
- CLUSTER BY 句CLUSTER BY clause
- 共通テーブル式 (CTE)Common table expression (CTE)
- DISTRIBUTE BY 句DISTRIBUTE BY clause
- GROUP BY 句GROUP BY clause
- HAVING 句HAVING clause
- [ヒント]Hints
- インライン テーブルInline table
- JOINJOIN
- LATERAL VIEW 句LATERAL VIEW clause
- LIKE 述語LIKE predicate
- LIMIT 句LIMIT clause
- ORDER BY 句ORDER BY clause
- PIVOT 句PIVOT clause
- サンプリング クエリSampling queries
- 集合演算子Set operators
- SORT BY 句SORT BY clause
- テーブル値関数 (TVF)Table-valued function (TVF)
- WHERE 句WHERE clause
- ウィンドウ関数Window functions