要实现的树如图所示,要求能根据“节点1”获取其所有子节点
数据库表设计如下:
在这里用到With As
WITH tb AS { SELECT* FROM node WHERE nodeId=1 UNION ALL SELECT node.nodeId,node.nodeName,node.parentId FROM node,tb WHERE node.parentId=tb.nodeId } SELECT * FROM tb
时间: 2024-10-08 16:57:53
要实现的树如图所示,要求能根据“节点1”获取其所有子节点
数据库表设计如下:
在这里用到With As
WITH tb AS { SELECT* FROM node WHERE nodeId=1 UNION ALL SELECT node.nodeId,node.nodeName,node.parentId FROM node,tb WHERE node.parentId=tb.nodeId } SELECT * FROM tb