在MSSQL 2008中使用多个CTE时,我通常用逗号分隔它们。
但是当我在Teradata环境中尝试这个时,我的语法出错了。
适用于MS SQL:
WITH CTE1 AS
(SELECT TOP 2 Name FROM Sales.Store)
,CTE2 AS
(SELECT TOP 2 ProductNumber, Name FROM Production.Product)
,CTE3 AS
(SELECT TOP 2 Name FROM Person.ContactType)
SELECT * FROM CTE1,CTE2,CTE3
现在,尝试使用Teradata语法:
WITH RECURSIVE CTE1 (Name) AS
(SELECT TOP 2 Name FROM Sales.Store)
,RECURSIVE CTE2 (ProductNumber, Name) AS
(SELECT TOP 2 ProductNumber, Name FROM Production.Product)
,RECURSIVE CTE3 (Name) AS
(SELECT TOP 2 Name FROM Person.ContactType)
SELECT *
FROM CTE1,CTE2,CTE3
语法错误,预期类似于名称或Unicode分隔 ','和'RECURSIVE'关键字之间的标识符。
第二次尝试(多次不使用RECURSIVE)
WITH RECURSIVE CTE1 (Name) AS
(SELECT TOP 2 Name FROM Sales.Store)
,CTE2 (ProductNumber, Name) AS
(SELECT TOP 2 ProductNumber, Name FROM Production.Product)
,CTE3 (Name) AS
(SELECT TOP 2 Name FROM Person.ContactType)
SELECT *
FROM CTE1,CTE2,CTE3
不支持多个WITH定义。
答案 0 :(得分:3)
Teradata 14.0版支持多个CTE。您可以从Teradata Developer Network网站下载TD v14 for VMware并进行测试。