SQL SERVER数据库中的递归CTE查询

2014-11-24 08:31:02 来源: 作者: 浏览: 2

SQL SERVER 数据库中的递归CTE查询
表名“TH_PRIVILEGE”
查询语句:with tt(l,ID,NAME,PID) as(
select l=case when PID IS null then 1 when PID IS not null then 2 end,ID,NAME,PID from TH_PRIVILEGE www.2cto.com
union all
select l=case when t1.PID IS null then 1 when t1.PID IS not null then 2 end,t1.ID,t1.NAME,t1.PID from TH_PRIVILEGE t1
inner join
tt b
on t1.ID=b.PID
)
select distinct(ID),NAME,PID,l from tt;
查询结果:


-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: