如何在SQL Server的子查询中使用CTE?

问题描述:

如何在sql server的子查询中使用CTE?

How we can use CTE in subquery in sql server?

like ..

选择
id
(我想在这里使用CTE),
name
from table_name

select id (i want to use CTE here), name from table_name

仅在顶部定义您的CTE并在子查询中访问它即可?

Just define your CTE on top and access it in the subquery?

WITH YourCTE(blubb) AS
(
    SELECT 'Blubb'
)
SELECT id,
       (SELECT blubb FROM YourCTE),
       name
FROM   table_name