flink sql CREATE TABLE AS SELECT
时间: 2023-08-08 13:08:17 浏览: 397
"CREATE TABLE AS SELECT" 是 Flink SQL 中的一种语法,用于创建一个新的表并将查询结果插入该表中。
具体语法如下:
```sql
CREATE TABLE new_table_name AS SELECT * FROM source_table_name;
```
其中,new_table_name 表示新创建的表名,source_table_name 则表示原始表名,* 表示查询结果中的所有列。该语句会将 source_table_name 中的数据插入到 new_table_name 中,如果 new_table_name 已经存在,则会覆盖原有的表。
除了 * 外,还可以指定查询结果中的特定列,例如:
```sql
CREATE TABLE new_table_name (col1 INT, col2 STRING) AS SELECT col1, col2 FROM source_table_name;
```
该语句会创建一个新表 new_table_name,其中包含两个列 col1 和 col2,并将 source_table_name 中的对应列插入到新表中。
相关问题
flink 1.14版本 怎么用 create table as select
在 Flink 1.14 版本中,可以使用以下语句创建新表并将查询结果插入其中:
```sql
CREATE TABLE new_table_name
WITH (
'connector' = 'filesystem',
'path' = '/path/to/new_table_name',
'format' = 'csv'
)
AS
SELECT * FROM source_table_name;
```
其中,new_table_name 表示新表的名称,/path/to/new_table_name 表示新表在文件系统中的路径,csv 表示新表的数据格式,可以根据具体需要调整。通过 WITH 子句指定表的连接器、路径和格式等属性,AS 子句后面的 SELECT 语句用于指定要插入到新表中的数据。
除了 * 外,还可以指定要查询的特定列,例如:
```sql
CREATE TABLE new_table_name
WITH (
'connector' = 'filesystem',
'path' = '/path/to/new_table_name',
'format' = 'csv'
)
AS
SELECT col1, col2 FROM source_table_name;
```
该语句会创建一个新表 new_table_name,并将 source_table_name 中的 col1 和 col2 列插入到新表中。注意,在使用 CREATE TABLE AS SELECT 语句时,新表的连接器、路径和格式等属性都需要指定。
Flink sql 语法
Flink SQL 是一个用于处理流和批处理数据的 SQL 引擎,使用 SQL 方式来进行数据流处理和数据分析。下面是 Flink SQL 的语法:
1. 创建表
```
CREATE TABLE table_name (
column_1 data_type,
column_2 data_type,
...
) [WITH (property_1=value_1, property_2=value_2, ...)];
```
2. 插入数据
```
INSERT INTO table_name (column_1, column_2, ...) VALUES (value_1, value_2, ...);
```
3. 查询数据
```
SELECT column_1, column_2, ... FROM table_name [WHERE condition];
```
4. 更新数据
```
UPDATE table_name SET column_1 = value_1 [, column_2 = value_2, ...] [WHERE condition];
```
5. 删除数据
```
DELETE FROM table_name [WHERE condition];
```
6. 聚合函数
Flink SQL 支持以下聚合函数:
- COUNT()
- SUM()
- AVG()
- MIN()
- MAX()
7. GROUP BY 子句
```
SELECT column_1, column_2, ..., aggregate_function(column_n)
FROM table_name
GROUP BY column_1, column_2, ...;
```
8. JOIN 操作
```
SELECT column_1, column_2, ...
FROM table_1 JOIN table_2
ON table_1.column = table_2.column;
```
以上是 Flink SQL 的基本语法,还有更多高级的特性可以在 Flink 官方文档中了解。
阅读全文
相关推荐














