在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定义。
Teradata的14.0版支持多个CTE。您可以从Teradata开发人员网络网站下载适用于VMware的TD v14并进行测试。