sql语句,根据id查询所有子级,包括当前父级(无限层级)
WITH RECURSIVE locs(id,pid,name)
AS
(
SELECT a.id,a.pid,a.name,0 AS loclevel FROM user a
where a.id='47dbe7d9-96bf-414e-b318-cb288b0f381b'
UNION ALL
SELECT a.id,a.pid,a.name,loclevel+1 FROM user a
INNER JOIN locs p ON a.pid=p.id
)
SELECT * FROM locs
##id 主键id
##pid 父级id