Amazon Redshift
数据库开发人员指南 (API Version 2012-12-01)
AWS 服务或AWS文档中描述的功能,可能因地区/位置而异。点 击 Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

SELECT INTO

选择任何查询所定义的行,并将这些行插入到新的临时表或永久表中。

语法

Copy
[ 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 表:

Copy
select * into newevent from event;

选择聚合查询的结果并将这些结果插入到名为 PROFITS 的临时表中:

Copy
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;

本页内容: