首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么在查询中把SUM()的结果加起来

2012-02-08 
如何在查询中把SUM()的结果加起来?我遇到这样一个问题数据库访问速度比较慢所以想尽可能减少查询的次数现

如何在查询中把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

热点排行