`
hellodajun
  • 浏览: 61508 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Sql server2005 递归查询

阅读更多

with DEPT1 as(  

        select DEPARTID ,PARENTID from DEPARTMENT  

    ),  

    DEPT2 as(  

        select * from DEPT1 where DEPARTID=8  

        union all  

        select DEPT1.* from DEPT2 inner join DEPT1   

        on DEPT2.PARENTID=DEPT1.DEPARTID  

    ) 

select * from DEPT2 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics