第1个回答 2011-01-11
select sum(金额) as 总金额, sum(合计) as 总计 from
(select 单位,金额,合计 from A
union all
select 单位,金额,合计 from B
union all
select 单位,金额,合计 from C
union all
select 单位,金额,合计 from D) as all
如果,要按单位分组的话,再加上group by子句:
select 单位, sum(金额) as 总金额, sum(合计) as 总计 from
(select 单位,金额,合计 from A
union all
select 单位,金额,合计 from B
union all
select 单位,金额,合计 from C
union all
select 单位,金额,合计 from D) as all
group by 单位
第2个回答 2011-01-11
select 单位,sum(合计) as 合计 from (
select 单位,单价,合计 from a union all
select 单位,单价,合计 from b union all
select 单位,单价,合计 from c union all
select 单位,单价,合计 from c
) t
group by 单位
order by 单位
第3个回答 2011-01-11
select all_four.单位,sum(all_four.金额) from (select 单位,金额 from A union select 单位,金额 from B union select 单位,金额 from C union select 单位,金额 from D) all_four
group by all_four.单位