按要求导出组织结构数据,SQL 查询语句

来源:互联网 发布:网页美工招聘 编辑:程序博客网 时间:2024/05/02 02:45
with jxs as (-- 经销商select id as jxs_id -- 经销商, parent_id as jxs_parent_id -- 经销商上级from t_departmentwhere position_id = 5),jl as (-- 经理select jxs.*, t1.id as jl_id -- 经理, t1.parent_id as jl_parent_id -- 经理上级from jxs left join t_department t1 on jxs.jxs_parent_id = t1.id) ,bbz as (-- 本部长select jl.*, t1.id as bbz_id -- 本部长, t1.parent_id as bbz_parent_id -- 本部长上级from jl left join t_department t1 on jl.jl_parent_id = t1.id),ls as (-- 理事select bbz.*, t1.id as ls_id -- 理事, t1.parent_id as ls_parent_idfrom bbz left join t_department t1on bbz.bbz_parent_id = t1.id),fz as (-- 副总select ls.*, t1.id as fz_idfrom ls left join t_department t1on ls.ls_parent_id = t1.id)select * from fz