Oracle递归操作

时间:2023-03-09 05:54:50
Oracle递归操作

需求:找出代理商中没有挂商家的代理商

Oracle递归操作

简单SQL如下:

select *
from t_proxy tp
where tp.id not in
(SELECT tp.id as p_id
FROM t_proxy tp
start with tp.id in (select distinct tm.proxy_id
from t_merchant tm
where tm.proxy_id is not null)
connect by prior tp.parent_id = tp.id)