弄一个笨点的,初学,勿笑!
select ID,货品,区域,new单价 as 单价 from
(select distinct name,ID,货品, 区域 from
(select ID&货品&区域 as name,ID,货品, 区域 from
(select ID,商品 as 货品,'0' as 区域,单价 from [sh1$] union
select ID,货品, 区域,单价 from [sh2$]
union
select ID,货品,区域,'0' as 单价 from [sh3$])
where not isNull(ID))) b,
(select sum(单价) as new单价,name from
(select ID&货品&区域 as name,ID,货品, 区域,单价 from
(select ID,商品 as 货品,'0' as 区域,单价 from [sh1$] union
select ID,货品, 区域,单价 from [sh2$]
union
select ID,货品,区域,'0' as 单价 from [sh3$])
where not isNull(ID))
group by name) a
where a.name=b.name |