菜鸟刚工作。最近在做一个项目。资源库工具的更新,也就是这个资源库跟数据库相连接,不过在这个资源库里面操作很方便。目前要实现这样一个功能。比如说,如图


就是这样的一个表,把他们的信息存储到这里面,然后点某一个文件夹,遍历一下这个表,把这个文件夹下的东西显示出来。
那个我想问一下各位大大,有没有什么sql语句可以直接实现这个功能,而不用这样麻烦。或者是用一种别的方式来实现。=。= 万分感谢!
------解决思路----------------------
declare @ClickID int =0;
select @ClickID=CAST( RAND()*4 as int)+1;
--drop table #TestData;
with TestData(id,pid,name,type,date) as (
select cast(1 as int),cast(0 as int),'A','Dir',getdate() union all
select 2,1,'B','Dir',getdate() union all
select 3,1,'C','Dir',getdate() union all
select 4,3,'D','Dir',getdate() union all
select 5,1,'X.TXT','File',getdate() union all
select 6,2,'L.HTML','File',getdate() union all
select 7,2,'XZ.HTML','File',getdate() union all
select 8,3,'CX.TXT','File',getdate() union all
select 9,4,'HELLO.CPP','File',getdate()
)
select * into #TestData from TestData;
select * from #TestData where id=@ClickID;--显示点击的文件夹
with cte as (
select *,1 lvl
from #TestData where id=@ClickID
union all
select t.*,cte.lvl+1
from #TestData t
join cte on cte.id=t.pid
)
select * from cte where lvl=2--显示所点文件夹内的内容
------解决思路----------------------
标准的BOM或组织架构图效果