CTE语法问题

时间:2015-09-30 13:59:31

标签: sql-server

以下代码有什么问题?

WITH CTE2 AS
(
select 1 as id
union
select 2
),
with CTE3 AS
(
    select * from CTE2
)
select * from CTE3

失败,语法错误。

2 个答案:

答案 0 :(得分:4)

不需要第二个WITH

;WITH CTE2 AS
(
  select 1 as id
  union
  select 2
), CTE3 AS
(
   select * from CTE2
)
select * 
from CTE3;

答案 1 :(得分:0)

您的代码中不需要额外的$key = substr(md5('mylittlepony').sha1('flutershyismylove'), 0, 31);

使用多个CTE时,您可以用逗号分隔它们,不需要多个WITH

WITH