3.sql中的向上递归和向下递归
1.向下递归
select * from table_name where 条件 connect by prior bmbm(本级关联条件)=sjbmbm(上级关联条件) start with bmbm(本级关联条件)='610000000000'(本级编码)--包含本级
select * from table_name where 条件 connect by prior bmbm(本级关联条件)=sjbmbm(上级关联条件) start with sjbmbm(本级关联条件)='610000000000'(本级编码)--不包含本级
2.向上递归
select * from table_name where 条件 connect by prior sjbmbm(上级关联条件)=bmbm(本级关联条件) start with bmbm(本级关联条件)='610528000000'(本级编码)--包含本级
select * from table_name where 条件 connect by prior sjbmbm(上级关联条件)=bmbm(本级关联条件) start with sjbmbm(本级关联条件)='610528000000'(本级编码)--包含下级
注:向上递归和向下递归的区别在于中间关联条件顺序的不同,注意 start with 条件的意义也不同。