在 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
语法错误,在 ',' 和 'RECURSIVE' 关键字之间应有名称或 Unicode 分隔标识符。
第二次尝试(不使用 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 定义。