数据库查询所有上级和下级语句

(SELECT @r AS _member_id, 
		(SELECT @r := tm_yaoqing 
		FROM tb_member
		WHERE tm_id= _member_id) AS tm_yaoqing, @l := @l + 1 AS lvl 
		FROM
		(SELECT @r := 101 , @l := 0 ) vars, 
		tb_member h 
		WHERE @r != 0) T1
SELECT 
		@ids as _ids, 
		( SELECT @ids := GROUP_CONCAT(tm_id) 
		FROM tb_member 
		WHERE FIND_IN_SET(tm_yaoqing, @ids) 
		) as cids, 
		@l := @l+1 as lvl 
		FROM tb_member, 
		(SELECT @ids := 130342, @l := 0 ) b 
		WHERE @ids IS NOT NULL

 

你可能感兴趣的:(SQL,查询上级)