递归层级查询:start with connect by prior 以部门表作为解析 表结构:dept{id:'主键',name:'部门名称',parent_id:'父亲id'} select * from dept start with id=1 connect by prior id= parent_idorder siblings by id 分两部分理解: 第一步找出一条数据作为基础:select * from dept start with id =? 第二步prior放在左边还是
需求:找出代理商中没有挂商家的代理商 简单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)
create or replace function fn_DeptWholeName2(objectid in number) return nvarchar2 is wholename nvarchar2(500); beginselect to_char(replace(wm_concat(OBJNAME),',','.'))a into wholename from (select * from v_organddept2 ostart with o.objid=objectidconn
每个地区递归层级可能不一致,数据表(table)存放最小层级地区 area --地区层级表 id name f_id leve 1 中国 0 1 2 湖北 1 2 3 武汉 2 3 ... --测试数据 with area(id,"name",f_id,leve) as ( ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,, union all ,,