SQL2000 用子节点查最高父节点,并计算相乘数量。

SQL2000 用子节点查最高父节点,并计算相乘数量。,第1张

create table tmp

(

PARTNAME varchar(50),

QTY int,

CHILD_ID varchar(50),

PARENT_ID varchar(50)

)

GO

declare @name varchar(50)

set @name='AA'

insert into tmp

select distinct t2PARTNAME, t1QTYt2QTY,t2CHILD_ID,t2PARENT_ID from tree t1,tree t2 where t1PARENT_ID=t2CHILD_ID and t1PARTNAME=@name

while exists(select from tmp t1,tree t2 where t1PARENT_ID=t2CHILD_ID and t2PARTNAME not in(select PARTNAME from tmp))

begin

insert into tmp

select distinct t2PARTNAME, t1QTYt2QTY,t2CHILD_ID,t2PARENT_ID from tmp t1,tree t2 where t1PARENT_ID=t2CHILD_ID and t2PARTNAME not in(select PARTNAME from tmp)

end;

select PARTNAME,QTY,CHILD_ID from tmp where PARENT_ID=0

drop table tmp

这个很简单啊

表结构一般如下tablename(表名)

id--节点ID, name-- 节点名称 parentid父节点ID,

-----获取节点号为6下的所有子节点

select from tablename t start with id =6 connect by prior id=parentid

SQL Server 2005:

架构dbo的所有表

select t[name] as tablename, s[name] as [schema] from systables as t,sysschemas as s where tschema_id = sschema_id

and s[name] = 'dbo'

架构dbo的所有视图

select v[name] as viewname, s[name] as [schema] from sysviews as v,sysschemas as s where vschema_id = sschema_id

and s[name] = 'dbo'

以上就是关于SQL2000 用子节点查最高父节点,并计算相乘数量。全部的内容,包括:SQL2000 用子节点查最高父节点,并计算相乘数量。、SQL通过父节点获取所有子节点、sql中一个表中父子表中列出所有的结构等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/9723400.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-05-01
下一篇2023-05-01

发表评论

登录后才能评论

评论列表(0条)

    保存