现有表 T1(Pid,subPid,Quantity)
pid int :零件编号
subpid int : 子零件编号
Quantity : 数量数据
pid subpid Quantity
102 104 2
102 105 2
104 106 3
104 109 1
105 107 3
107 108 1这个表,表示 102 这个零件有哪些子零件组成。数量要多少
用树型表示就是 102
|- 104
|- 106
|- 109
|- 105
|- 107
|- 108要求,我给出一个 102
得到结果如下
最小单位
零件编号 个数
106 6
109 2
108 6
pid int :零件编号
subpid int : 子零件编号
Quantity : 数量数据
pid subpid Quantity
102 104 2
102 105 2
104 106 3
104 109 1
105 107 3
107 108 1这个表,表示 102 这个零件有哪些子零件组成。数量要多少
用树型表示就是 102
|- 104
|- 106
|- 109
|- 105
|- 107
|- 108要求,我给出一个 102
得到结果如下
最小单位
零件编号 个数
106 6
109 2
108 6
解决方案 »
- 请问用delphi 怎么将TIF 文件合并成PDF
- 用Delphi如何转出Excel档???
- DELPHI三层数据库架构设计方案(原创2)
- WPS2005的Gui是用Delphi写的
- Borland的Together,为什么不能生成Delphi语言源代码?
- delphi2010中clientdataset的field name missing
- delphi7 中用ADO访问 Excel文件 XP下可以,win7 下错误?搞不懂
- delphi2009的数据类型转换和Deiphi以前版本的有什么差异?比如PChar
- 高分求解!如何编程改变边框为bsNone的窗体的大小?可以利用WM_NCHitTest,也可以利用其他方法,但边框限制为bsNone。给我一个例子。
- 如何编程实现html到chm的转换?和rtf到hlp的转换?象耶書制造那样的。(谁有源码,或者相关资料?)
- DCOM COM+ 三层 如何穿透防火墙,请看这里--转一篇文章
- 录入界面继承后,动态创建ADOQuery,DataSource,做不出来.~~
where subpid not in
(SELECT DISTINCT pid from T1)
由子零件去指向其父零件, ID(零件ID)
PID(父零件ID)(若为根则为0)
Quantity(个数)
RETURNS int AS
BEGIN
declare @pid int,@tempid int
set @pid=(select pid from testtb where subpid=@subpid)
if @pid is not NULL
set @tempid=dbo.FindOwner(@pid)
else
set @tempid=@subpid
return @tempid
ENDCREATE PROCEDURE [dbo].[CalcQuantity] @pid int AS
select subpid as pid,sum(Quantity) as SumQuantity
from testtb
where dbo.FindOwner(subpid)=@pid
group by subpid
GO--最后执行为
exec CalcQuantity 102
Select pid subpid ,Sum(Quantity) From T1 group by pid subpid
现在接点的时候过滤以下就OK了,一次汇总总比你没现在选择一个接点调用一次存储过程执行效率高吧
--
oracle实现
select Pid,subPid,Quantity from T1 CONNECT BY prior subPid=Pid START WITH Pid =102你下次问问题时,最好说用什么数据库