时间:2021-07-01 10:21:17 帮助过:3人阅读
根据节点查询所有父节点 CREATE DEFINER=`root`@`localhost` FUNCTION `getParentList`(rootId varchar(100)) RETURNS varchar(1000) CHARSET latin1 BEGIN DECLARE fid varchar(100) default ‘‘; DECLARE str varchar(1000) default rootId; WHILE rootId is not null do SET fid =(SELECT parent_id FROM tree WHERE id = rootId); IF fid is not null THEN SET str = concat(str, ‘,‘, fid); SET rootId = fid; ELSE SET rootId = fid; END IF; END WHILE; return str; END select * from tree where FIND_IN_SET(Id,getParentList(‘589bde6b-b432-4563-9101-8ec93161e398‘))
MySql 根据节点查询父节点或子节点
标签:int arch mysq arc efault default find mysql pre