根据父节点查询子节点 子子节点

WITH RECURSIVE tmp_table (item_class_code, parent_class_code) AS
(
  -- 基础查询:‌选择初始父节点
  SELECT item_class_code, parent_class_code
  FROM item_class
  WHERE item_class_code = '74'  -- 用实际的父节点ID替换问号
  UNION ALL
  -- 递归查询:‌根据已找到的子节点继续寻找下一级子节点
  SELECT c.item_class_code, c.parent_class_code
  FROM item_class c
  INNER JOIN tmp_table tt ON tt.item_class_code = c.parent_class_code
)
SELECT * FROM tmp_table;
posted @ 2024-08-27 13:25  Arborblog  阅读(27)  评论(0编辑  收藏  举报