MSSQL中递归SQL查询语句实例说明

jw_fengying 19 0 PDF 2020-12-17 18:12:37

一张表(ColumnTable)的结构如下图所示 当前需要实现的功能:通过Number的值为67来获取当前的节点ID、父节点ID 递归实现SQL语句: 代码如下: with znieyu as ( select c.Id,c.FatherId,0 as lv1 from ColumnTable c where c.Number=67 union all select c.Id,c.FatherId,lv1-1 from znieyu z inner join ColumnTable c on z.FatherId=c.Id ) select znieyu.Id ,znieyu.FatherI

用户评论
请输入评论内容
评分:
暂无评论