我可以根据使用with
子句形成的查询创建表吗?
答案 0 :(得分:48)
当然:
CREATE TABLE t
AS
WITH some_data AS (
SELECT 1 as some_value
FROM dual
UNION ALL
SELECT 2
FROM dual
)
SELECT *
FROM some_data
答案 1 :(得分:1)
CREATE TABLE table_name AS语句基于select语句创建表。 with子句的解决方案是:
CREATE TABLE t
AS
SELECT * FROM (
WITH some_data AS (
SELECT 1 as some_value
FROM dual
UNION ALL
SELECT 2
FROM dual
)
);
答案 2 :(得分:0)
对于多个CTE(公用表表达式;即多个WITH
子句),我发现相同的语法有效。即
CREATE TABLE schema.table_name as
WITH table1 as (SELECT 1),
table2 as (SELECT 2)
select * from table2
将从table_name
语句的schema
中创建select