SELECT INTO - Amazon Redshift

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

SELECT INTO

選取任何查詢所定義的資料列,然後將它們插入新的資料表中。您可以指定是否建立臨時或永久資料表。

Syntax (語法)

[ WITH with_subquery [, ...] ] SELECT [ TOP number ] [ ALL | DISTINCT ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table [ FROM table_reference [, ...] ] [ WHERE condition ] [ GROUP BY expression [, ...] ] [ HAVING condition [, ...] ] [ { UNION | INTERSECT | { EXCEPT | MINUS } } [ ALL ] query ] [ ORDER BY expression [ ASC | DESC ] [ LIMIT { number | ALL } ] [ OFFSET start ]

如需有關此命令之參數的詳細資訊,請參閱 SELECT

範例

從 EVENT 資料表選取所有資料列,並建立 NEWEVENT 資料表:

select * into newevent from event;

將彙整查詢的結果選入名為 PROFITS 的臨時資料表中:

select username, lastname, sum(pricepaid-commission) as profit into temp table profits from sales, users where sales.sellerid=users.userid group by 1, 2 order by 3 desc;