当前位置:   article > 正文

MySQL查询某个子节点的顶级节点(根节点)_nysql5.7查子节点的顶级父节点

nysql5.7查子节点的顶级父节点

MySQL查询某个子节点的顶级节点(根节点)

SELECT
	T2.* 
FROM
	(
	SELECT
		@r AS _id,
		( SELECT @r := parent_id FROM `look_project_process` WHERE id = _id ) AS 2v2,
		@l := @l + 1 AS lvl 
	FROM
		( SELECT @r := 'e718165baece49678359dd945371f93e', @l := 0 ) vars,
		look_project_process h 
	
	) T1
	LEFT JOIN look_project_process T2 ON T1._id = T2.id 
WHERE
	T2.parent_id IS NULL and T2.id is not null
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/442200
推荐阅读
相关标签
  

闽ICP备14008679号