select a.* from tbl_user a where a.department_id in(SELECT u2.id
FROM(
SELECT
@ids AS p_ids,
(SELECT @ids := GROUP_CONCAT(id) FROM tbl_department WHERE FIND_IN_SET(parent_id, @ids)) AS c_ids,
@l := @l+1 AS LEVEL
FROM tbl_department, (SELECT @ids := ‘504956078’, @l := 0 ) b
WHERE @ids IS NOT NULL
) u1
JOIN tbl_department u2
ON FIND_IN_SET(u2.id, u1.p_ids) AND u2.id != ‘504956078’)
sql递归查询
最新推荐文章于 2024-06-14 08:00:00 发布