|
大神们请问如下sql 代码可以用pandas 实现吗?
谢谢大神们了,自己研究还就没有结果:
with t as
(
select *,1 lvl from bom where 父件编码=@No
union all
select a.父件编码,a.子件编码,a.用量*b.用量,b.lvl+1 from bom a,t b where a.父件编码=b.子件编码
)
select 子件编码 as 编码,用量
from t a
完整的存储过程是这样:
If not object_id('extend_bom') is null
Drop PROCEDURE extend_bom
Go
If not object_id('f_getbom') is null
Drop function f_getbom
Go
create function f_getbom(@No varchar(10),@lvl int)
returns table
as
return
with t as
(
select *,1 lvl from bom where 父件编码=@No
union all
select a.父件编码,a.子件编码,a.用量*b.用量,b.lvl+1 from bom a,t b where a.父件编码=b.子件编码
)
select 子件编码 as 编码,用量
from t a
where lvl<=@lvl
and not exists(
select 1
from t
where lvl<=@lvl
and a.子件编码=父件编码)
go
谢谢大神们了!
|
|