设为首页收藏本站

EPS数据狗论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1671|回复: 0

SQL根据指定节点ID获取所有父级节点和子级节点

[复制链接]

16

主题

176

金钱

267

积分

入门用户

发表于 2019-8-9 15:26:47 | 显示全部楼层 |阅读模式

根据指定节点ID获取所有父节点
  1. with temp as(
  2. select * from dbo.Category where Id=493 --表的主键ID
  3. union all
  4. select t.* from temp,dbo.Category t where temp.Pid=t.Id --父级ID=子级ID
  5. )select * from temp order by Level;
复制代码

1.png

根据指定节点ID获取所有子节点
  1. with temp as(
  2. select * from dbo.Category where Id=344 --表的主键ID
  3. union all
  4. select t.* from temp,dbo.Category t where temp.Id=t.Pid --子级ID==父级ID
  5. )select * from temp;
复制代码

2.png
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

客服中心
关闭
在线时间:
周一~周五
8:30-17:30
QQ群:
653541906
联系电话:
010-85786021-8017
在线咨询
客服中心

意见反馈|网站地图|手机版|小黑屋|EPS数据狗论坛 ( 京ICP备09019565号-3 )   

Powered by BFIT! X3.4

© 2008-2028 BFIT Inc.

快速回复 返回顶部 返回列表