以下是來自PostgreSQL documentation的SELECT
的簡介。在我看來,有時我們寫<expression> AS <name>
,有時候是<name> AS <expression>
。在普通的英語,我傾向於認爲<expression> AS <name>
是更常見(如「地址她。史密斯博士,謝謝。,而我無法理解如何看待<name> AS <expression>
。'AS'在SQL中的含義是什麼?
- 我們如何能區別在哪裏使用
<name> AS <expression>
和<expression> as <name>
區別? - 什麼是每一個?
- 最小明顯的例子是有各種普通的語言,這將使它非常直觀何時使用什麼相似之處?
[ WITH [ RECURSIVE ] with_query [, ...] ] SELECT [ ALL | DISTINCT [ ON (expression [, ...]) ] ] * | expression [ [ AS ] output_name ] [, ...] [ FROM from_item [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ WINDOW window_name AS (window_definition) [, ...] ] [ { UNION | INTERSECT | EXCEPT } [ ALL | DISTINCT ] select ] [ ORDER BY expression [ ASC | DESC | USING operator ] [ NULLS { FIRST | LAST } ] [, ...] ] [ LIMIT { count | ALL } ] [ OFFSET start [ ROW | ROWS ] ] [ FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } ONLY ] [ FOR { UPDATE | SHARE } [ OF table_name [, ...] ] [ NOWAIT ] [...] ] where from_item can be one of: [ ONLY ] table_name [ * ] [ [ AS ] alias [ (column_alias [, ...]) ] ] (select) [ AS ] alias [ (column_alias [, ...]) ] with_query_name [ [ AS ] alias [ (column_alias [, ...]) ] ] function_name ([ argument [, ...] ]) [ AS ] alias [ (column_alias [, ...] | column_definition [, ...]) ] function_name ([ argument [, ...] ]) AS (column_definition [, ...]) from_item [ NATURAL ] join_type from_item [ ON join_condition | USING (join_column [, ...]) ] and with_query is: with_query_name [ (column_name [, ...]) ] AS (select | values | insert | update | delete) TABLE [ ONLY ] table_name [ * ]
公共表格表達式的「as」在例如相同的情況下是相同的。 'create view foo AS select ...'或者在'create table xy AS select ...'中。名稱和別名的重載用法由SQL標準定義,它不是Postgres發明的。 –