日期:2014-05-19  浏览次数:20634 次

如何在查询中把SUM()的结果加起来?
我遇到这样一个问题   数据库访问速度比较慢
所以想尽可能减少查询的次数
现在有两个表中有一个相同的字段分别用SUM()求和
请问怎么在一条查询中把对两个表的SUM()结果加起来?
谢谢


------解决方案--------------------
select (select sum(a.field1) from a) + (select sum(b.field1) from b)
------解决方案--------------------
Select Sum(a.字段1) from (Select aa as '字段1 ' from A表 union all Select bb as '字段1 ' from B表) a
------解决方案--------------------
改一下青锋老弟的
declare @i int,@j int
select @i=sum(a.field1) from a
select @j=sum(b.field1) from b
select @i+@j