mysql 查询所有父级,子级

 

mysql 遍历查询所有父级:

SELECT T1._id groupID

FROM (
SELECT
@r AS _id,
(SELECT @r := fbh FROM business_group WHERE bh = _id) AS fbh,
@l := @l + 1 AS lvl FROM (SELECT @r := #{groupID}, @l := 0) vars,
business_group h WHERE @r != '0'
) T1

 

 

mysql 遍历查询所有子级:

SELECT
concat_ws( ',', #{majorGuid}, GROUP_CONCAT( guId ) )
FROM
( SELECT * FROM base_jc_profession_field_content ) realname_sorted,
( SELECT @pv := #{majorGuid} ) initialisation
WHERE
( FIND_IN_SET( parent_guId, @pv ) > 0 AND @pv := concat( @pv, ',', guId ) )

 

posted @ 2019-12-26 14:30  xiaotian_小天  Views(4968)  Comments(0Edit  收藏  举报