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