搞了好久才搞好,主要是你没有数据源(6个表),我自己做了一个模拟的,以下的SQL语句,你参考一下吧。文件我就不传了。
select 地段,栋号,表1,表2,表3,表4,表5,表6,((表1+表2+表3+表4+表5+表6)/6) as 平均
from (select 地段,栋号,sum(合计金额) as 表1,0 as 表2,0 as 表3, 0 as 表4, 0 as 表5,0 as 表6 from [表1$] group by 地段,栋号 union all
select 地段,栋号,0,sum(合计金额),0,0,0,0 from [表2$] group by 地段,栋号 union all
select 地段,栋号,0,0,sum(合计金额),0,0,0 from [表3$] group by 地段,栋号 union all
select 地段,栋号,0,0,0,sum(合计金额),0,0 from [表4$] group by 地段,栋号 union all
select 地段,栋号,0,0,0,0,sum(合计金额),0 from [表5$] group by 地段,栋号 union all
select 地段,栋号,0,0,0,0,0,sum(合计金额) from [表6$] group by 地段,栋号) |