组织表字段id,及parentId,数据库mysql5.7
①解决的问题点:需要查出一个组织树结构,根据指定ID获取当前ID的所有子树。
select id,
parent_idfrom (select * from hrm_organization
order by parent_id, id) organization,
(select @pv := '18') initialisation
where find_in_set(parent_id, @pv) > 0
and @pv := concat(@pv, ',', id);
②解决的问题点:查出一条线性结构,查询当前ID的所有父级
SELECT
t.id,
@pv := t.parent_id
FROM
(
SELECT
*
FROM
hrm_organization
ORDER BY