SQL中如何将两个查询结果相加?
1个回答
展开全部
做个简单的。
两个数据表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
两个数据表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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询