select 父目錄,子目錄,用量,層次=1 from 表TEST1
union
select 父目錄,子目錄=(select 子目錄 from 表TEST1
where 子目錄 in (select 子目錄 from 表TEST1)
and 父目錄 in (select 子目錄 from 表TEST1)
),用量,層=2 from 表TEST1
union
select 父目錄,子目錄=(select 子目錄 from 表TEST1
where 子目錄 in (select 子目錄 from 表TEST1)
and 父目錄 in (select 子目錄 from 表TEST1)
),用量,層=2 from 表TEST1
解决方案 »
- 请问如何手动设置 SQL Server 内存选项?
- 怎么把字符段里的数字筛选出来
- 有什么办法可以使触发器暂时失效?
- 怎么选取某表中不在另一个表中的数据?
- 在数据表中设置默认值是否影响数据库的执行效率?
- 存储过程的问题,高手请进。
- 一个小问题
- 告诉我怎么取当前游标位置记录的某个字段的值怎么取?
- 一个7*24小时运行的系统运行一两天就出现“可用内存小于最小查询内存,请减少min memory per query 服务器培植选项的配置值"
- 高手请进:Delphi5.0与SqlServer 2000的问题!急!!!
- 为何使用以下语句导出到excel时候,excel中的列总是错位呢?
- 查找表中特殊(异常)的记录-----求一sql语句
create table TEST1(
父目錄 varchar(10),
子目錄 varchar(10),
用量 int
)
create table TEST2(
目錄 varchar(10)
)insert into test1 select rtrim('AA'),rtrim('AAA'),2
insert into test1 select rtrim('AA'),rtrim('AAB'),1
insert into test1 select rtrim('AA'),rtrim('AAC'),3
insert into test1 select rtrim('AAA'),rtrim('AAAAZ'),5
insert into test1 select rtrim('AAA'),rtrim('AAAB'),3
insert into test1 select rtrim('BB'),rtrim('BBA'),2
insert into test1 select rtrim('BB'),rtrim('BBB'),2
insert into test1 select rtrim('BBA'),rtrim('BBAAZ'),3 insert into test2 select 'AA'
insert into test2 select 'BB'
insert into test2 select 'AAA'
--查询
select
*,
1 as 層次
from
test1
where
父目錄 in(select 目錄 from test2)
union all
select
b.父目錄,
a.子目錄,
b.用量*a.用量,
2
from
test1 a,
test1 b
where
a.父目錄 = b.子目錄--删除测试数据
drop table test1
drop table test2
into #tmpbom
from
test1 where assm_no in (select assm_no form test2)
set @level=1
while @level<20
begin
insert into #tmpbom
select t.assm_no as assm_no,b.part_no, b.qty_per*t.qty_per as qty_per, @level+1 as idno
from test1 b (nolock)
join #tmpbom t on t.part_no=b.assm_no
where t.idno=@level
if @@rowcount=0
break
delete t from engbomm b join #tmpbom t on t.part_no=b.assm_no where t.idno=@level
set @level=@level+1
end 不知道這樣行不?