我有一个复杂的查询,可以创建其他CTE_Tables的主CTE_Table形式。我想将主CTE_Table的结果插入到物理表中。我正在使用Teradata 15.10.04.03版
SELECT失败。 [3707]语法错误,预期类似'SELECT'关键字或'('或'TRANSACTIONTIME'关键字或'VALIDTIME'关键字')和'INSERT'关键字。
DROP TABLE dbname.physicalTablename;
CREATE MULTISET TABLE dbname.physicalTablename, 没有回落, 没有在期刊之前, 没有后期, CHECKSUM =默认, DEFAULT MERGEBLOCKRATIO ( col1 INTEGER, col2 INTEGER, col3 INTEGER ) 没有主要指数;
使用
cteTable3 AS (SELECT A.colA,A.colB,A.colC,B.col1,B.col2,B.col3 FROM cteTable1 INNER JOIN cteTable2 ON(blah blah blah)),
cteTable2 AS (SELECT col1,col2,col3 FROM SourceTableB),
cteTable1 AS (SELECT colA,colB,colC FROM SourceTableA)
INSERT INTO dbname.physicalTablename
(col1,col2,col3,col4,col5,col6)
选择
(C3.colA,C3.colB,C3.colC,C3.col1,C3.col2,C3.col3)
来自cteTable3 C3;
答案 0 :(得分:0)
虽然您缺少问题的INSERT部分,但我认为以下内容可能会清除。在INSERT中使用CTE的正确格式是:
INSERT INTO <tablename>
WITH <cte> AS (SELECT...)
SELECT <fields> FROM <cte>
请考虑以下事项:
CREATE MULTISET VOLATILE TABLE tmp AS (SELECT 'bobby' as firstname) WITH DATA ON COMMIT PRESERVE ROWS;
INSERT INTO tmp
WITH cte AS (select 'carol' as firstname)
SELECT * FROM cte;
SELECT * FROM tmp;
DROP TABLE tmp;