MySql递归查询语句
程序员文章站
2022-05-12 18:52:01
...
MySql数据库,递归查询子节点
1.数据结构
表名:tb_organization 字段名: id,parent_id,code,name
2.查询语句
SELECT o2.* FROM (
SELECT @ids as _ids, ( SELECT @ids := GROUP_CONCAT(id) FROM tb_organization WHERE FIND_IN_SET(parent_id, @ids) ) as cids
FROM tb_organization, (SELECT @ids :='76350', @l := 0 ) b WHERE @ids IS NOT NULL
) id, tb_organization o2
WHERE FIND_IN_SET(o2.id, ID._ids)
ORDER BY id
1.数据结构
表名:tb_organization 字段名: id,parent_id,code,name
2.查询语句
SELECT o2.* FROM (
SELECT @ids as _ids, ( SELECT @ids := GROUP_CONCAT(id) FROM tb_organization WHERE FIND_IN_SET(parent_id, @ids) ) as cids
FROM tb_organization, (SELECT @ids :='76350', @l := 0 ) b WHERE @ids IS NOT NULL
) id, tb_organization o2
WHERE FIND_IN_SET(o2.id, ID._ids)
ORDER BY id
上一篇: 深入剖析 Java RMI 技术实现原理
下一篇: java远程调用方法总结