往上recursive mysql
SELECT @r AS _wgid,
(
SELECT @r := wgid_parent
FROM workgroup
WHERE wgid = _wgid
) AS parent,
@l := @l + 1 AS level
FROM (
SELECT @r := 10,
@l := 0,
@cl := 0
) vars,
workgroup h
WHERE @r <> 0
ORDER BY level DESC