SQL递归查询

  • oracle数据库:
update salt_sell_org_t t set t.orgid='11' where  t.id in (
select id from salt_sell_org_t s start with s.id='4028e4403dc02e84013dc05e4b8b0015' connect by prior s.id=s.pid );
s.id=s.pid ---从上往下找
s.pid=s.id---从下往上找
 
  •  sql server 数据库:
with cte_child(ID,ParentID,NAME)
as(
select ID,ParentID,NAME from Z_ORGANIZE_T where id = '"+orgId+"'
union all select a.ID,a.ParentID,a.NAME from Z_ORGANIZE_T a inner join cte_child b on ( a.ParentID=b.ID))
select ID from cte_child 

猜你喜欢

转载自louis-033.iteye.com/blog/2293078