摘 要:SQL 递归查询 with as方法 with as属于sql server新特性CTE(Common Table Expression)的关键字,用来储存临时结果集。常用于代替子查询。
正 文:
with temp ( [Id], [parentid])
as
(
select Id, parentid
from DiGui
where [parentid] = 15
union all
select a.Id, a.parentid
from DiGui a
inner join temp on a.[parentid] = temp.[Id]
)
select * from temp