用临时表了只能。
create table #temp (工程名称=?.? , 总造价= decimal(14,2), 材料造价 = decimal(14,2), 设备造价= decimal(14,2), ...)insert #temp
总造价= (select sum(??) from ?? where left(??,2)=11 and ??=??),
材料造价 = ()
..select * from #temp
create table #temp (工程名称=?.? , 总造价= decimal(14,2), 材料造价 = decimal(14,2), 设备造价= decimal(14,2), ...)insert #temp
总造价= (select sum(??) from ?? where left(??,2)=11 and ??=??),
材料造价 = ()
..select * from #temp
用left join 方法,
select A.工程编码,B.总造价
from
(select 工程编码
from dynamic )A
left join
(select 工程编码,总造价=sum(??)
where substring()=‘11'--取前两位判断是否11
group by 工程编码 )B
on A.工程编码 =B.工程编码
这只是一层,然后你一层一层的包下去,就可以了。
仓促之间,难免有误:)