SELECT T1.SortID,T1.lvl,T2.SortId, T2.SortName
FROM (
SELECT a.SortId,
@r AS _id,
(SELECT @r := PID FROM BSOrganizationSort WHERE SortId = @r ) AS PID,
@l := @l + 1 AS lvl
FROM
(
SELECT @r := '636181288126391811' as SortId, @l := 0
) a,
BSOrganizationSort h
WHERE @r <> 0) T1
JOIN BSOrganizationSort T2
ON T1._id = T2.SortId
ORDER BY T1.lvl DESC