在sql server 中, 怎么实现 oralce中的 start with, connect by 的写法

summergood 2003-11-25 09:44:49
我查了好久,大家知道吗? 谢谢!
...全文
255 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
BlueSuperMan 2004-03-02
  • 打赏
  • 举报
回复
同意:pengdali(大力 V3.0)de
summergood 2004-01-17
  • 打赏
  • 举报
回复
ing。。。
wifi2018 2004-01-08
  • 打赏
  • 举报
回复
up
summergood 2004-01-02
  • 打赏
  • 举报
回复
2004年了, 祝大家 happy new year, 望大家帮我解决这个问题啊!
summergood 2003-12-02
  • 打赏
  • 举报
回复
再次询问!
summergood 2003-11-27
  • 打赏
  • 举报
回复
说的不具体阿!
zjcxc 2003-11-25
  • 打赏
  • 举报
回复
如果是树形数据处理,参考:

树形数据的处理
http://expert.csdn.net/Expert/topic/2285/2285830.xml?temp=.2009699
pengdali 2003-11-25
  • 打赏
  • 举报
回复
http://expert.csdn.net/Expert/TopicView1.asp?id=2285830
pengdali 2003-11-25
  • 打赏
  • 举报
回复
/*--按父找子--*/
declare @a table (TC_Id int,TC_PID int,TC_Name varchar(200))
insert @a values(1,0,'中国')
insert @a values(2,0,'美国')
insert @a values(3,0,'加拿大')
insert @a values(4,1,'北京')
insert @a values(5,1,'上海')
insert @a values(6,1,'江苏')
insert @a values(7,6,'苏州')
insert @a values(8,7,'常熟')
insert @a values(9,6,'南京')
insert @a values(10,6,'无锡')
insert @a values(11,2,'纽约')
insert @a values(12,2,'旧金山')

declare @tmp1 table (TC_Id int,TC_PID int,TC_Name varchar(200),lev int)
insert @tmp1 select *,1 from @a where tc_ID=1
while @@rowcount>0
insert @tmp1 select a.*,1 from @a a,@tmp1 b where a.tc_pid=b.tc_ID and a.tc_ID not in (select tc_ID from @tmp1)
select * from @tmp1

/*--按子找父--*/
--建立环境
declare @a table (TC_Id int,TC_PID int,TC_Name varchar(200))
insert @a values(1,0,'中国')
insert @a values(2,0,'美国')
insert @a values(3,0,'加拿大')
insert @a values(4,1,'北京')
insert @a values(5,1,'上海')
insert @a values(6,1,'江苏')
insert @a values(7,6,'苏州')
insert @a values(8,7,'常熟')
insert @a values(9,6,'南京')
insert @a values(10,6,'无锡')
insert @a values(11,2,'纽约')
insert @a values(12,2,'旧金山')

declare @tmp1 table (TC_Id int,TC_PID int,TC_Name varchar(200))

--开始结点
insert @tmp1 select * from @a where tc_ID=10

--循环得到
while @@rowcount>0
insert @tmp1 select a.* from @a a,@tmp1 b where a.tc_id=b.tc_pID and a.tc_ID not in (select tc_ID from @tmp1)

--显示结果
select * from @tmp1

/*--遍厉所有--*/
declare @你的表 table (sortid int,parid int,sortname varchar(20))
insert @你的表 values(28,0,'包装')
insert @你的表 values(63,0,'安全防护')
insert @你的表 values(64,0,'办公')
insert @你的表 values(73,0,'电脑')
insert @你的表 values(74,63,'锁具')
insert @你的表 values(75,63,'防盗门')
insert @你的表 values(118,75,'普通防盗门')
insert @你的表 values(119,75,'豪华防盗门')
insert @你的表 values(120,28,'文化用纸')
insert @你的表 values(121,28,'包装用纸')
insert @你的表 values(122,28,'纸浆')
insert @你的表 values(123,63,'保险柜')
insert @你的表 values(124,63,'防身用具')
insert @你的表 values(125,73,'主机 ')
insert @你的表 values(126,73,'机箱')
insert @你的表 values(127,73,'软件')
insert @你的表 values(128,127,'财务软件')
insert @你的表 values(129,127,'系统管理软件')
insert @你的表 values(130,127,'工具软件软件')
insert @你的表 values(131,127,'数据库软件')


declare @tmp1 table (sortid int,parid int,sortname varchar(20),层次 int,所属分组 int)
declare @i int,@j int
select @i=1,@j=1

while exists(select 1 from @你的表 where parid=0 and sortid not in (select sortid from @tmp1))
begin
insert @tmp1 select top 1 *,@i,@j from @你的表 where parid=0 and sortid not in (select sortid from @tmp1) order by sortid
while @@rowcount>0
begin
set @i=@i+1
insert @tmp1 select a.*,@i,@j from @你的表 a,@tmp1 b where a.parid=b.sortid and a.sortid not in (select sortid from @tmp1)
end
select @j=@j+1,@i=1
end
select * from @tmp1
zjcxc 2003-11-25
  • 打赏
  • 举报
回复
没用过oracle.


start with, connect by

这两个是做什么的?

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧