mysql实现递归
select * from table start with id in (id个数未知)
connect by prior parent_id=id
这是oracle的,想转成mysql的
表结构
id name code parent_id
1 aaa 001 null
2 bbb 001.002 1
就是普通的树形结构,在线等啊!!!
mysql要想是想start with 得自己写个方法
CREATE FUNCTION `getChildList`(rootId varchar(100))
RETURNS varchar(2000)
BEGIN
DECLARE str varchar(2000);
DECLARE cid varchar(100);
SET str = '$';
SET cid = rootId;
WHILE cid is not null DO
SET str = concat(str, ',', cid);
SELECT group_concat(id) INTO cid FROM treeNodes where FIND_IN_SET(parentid, cid) > 0;
END WHILE;
RETURN str;
END
热门云产品限量秒杀,云服务器1核2G 14.5元/月起
https://dwz.cn/qVctf4jS