做个简单的。
两个数据表db1,db2
查询结果A是从数据表db1获取的:
select names, sale from db1
查询结果B是从数据表db2获取的:
select names, sale from db2
则查询结果C:
select names,sum(sale) as sale
from
(select names, sale from db1
union
select names, sale from db2
)
group by names
表A 表B
select ABC from A where ID=xxx
select ABC from B where nane = xxx
求和
select sum(ABC) from (select ABC from A where ID=xxx union select ABC from B where nane = xxx)