sql查询子孙节点和本身数据
我有一张表S_ROOM ,最多有三层结构。我输入名称后将他的子孙节点和自己都获取到。
数据有下面。如我输入总部,应该下面5条数据都出来。输入审计,结果出现 2,3.
id name parentId
1 总部 0
2 财务 1
3 审计 2
4 信息 1
5 内审 1
select * from s_room where parentid in(select id from s_room where parentid in ( select id from s_room where name='总部'))
or id in (select id from s_room where parentid in ( select id from s_room where name='总部')) or c_name='总部';
SELECT *
FROM S_ROOM D
CONNECT BY PRIOR D.ID = D.PARENTID
START WITH D.NAME = '财务'