SQL recursive query

  • oracle database:
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---find from top to bottom
s.pid=s.id---find from bottom to top
 
  •  sql server database:
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 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326948805&siteId=291194637
Recommended