读书人

sql 子查询的求教解决方法

发布时间: 2013-03-14 10:33:15 作者: rapoo

sql 子查询的求教
sql 子查询的求教解决方法
现在要利用浙江省民政厅的ORG_ID 查出所有市下面的登记处,求教
[解决办法]
with cte as
(
select * from tb where org_parent_id=-1
union all
select t.* from tb t join cte c on c.org_id=t.org_parent_id
)
select * from cte
[解决办法]
递归查询
;with cte as
(
select * from tb where ORG_PARENT_ID=-1
union all
select a.* from tb a inner join cte b on a.ORG_PARENT_ID=b.ORG_ID
)select * from cte

读书人网 >SQL Server

热点推荐