MySQL之查询所有子节点
SELECT
*
FROM
sys_menu
WHERE
id in (
select id from (
select t1.id,
if(find_in_set(parent_id, @pids) > 0, @pids := concat(@pids, ',', id), 0) as ischild
from sys_menu t1,
(select @pids := #{parentIds}
) t2
) t3 where ischild != 0
)
- parentIds 是需要查询数据的父节点ID,多个以逗号分隔,数据类型为字符串
- 例如 parentIds = '1547509717587218433,1495276092087394306'