sql中怎么将两个做了sum之后的值相加

A:select sum(a*b) from m , h
where type = 2 and m.code = h.code ;
B:select sum(a*b) from m , h1
where type = 2 and m.code = h1.code;
怎么做A+B?

1.打开一个数据中包含整数值的表,可以看到右下角的表数据。

2.在数据表中自动+1,如图所示,可以写入更新biao1集的年龄=年龄+1。

3.选择UPDATE biao1 SET age=age+1语句,点击左上角的执行查询按钮或按f9执行该语句,依次执行。

4.最后,将SQL修改为UPDATEbiao1SETage=age*2,执行这条语句,将字段x2中的值进行运算,那么就是结果的和。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-12-16
最简单的方法:
select ss1 +ss2 from(
(select sum(a*b) as ss1 from m , h
where type = 2 and m.code = h.code )s1,

(select sum(a*b) as ss2 from m , h1
where type = 2 and m.code = h1.code)s2)
这样就可以了,Oracle肯定可以,其它也应该可以,但是要注意ss1 和ss2如果为null的问题就可以了追问

报错了 缺失右括号

追答

(ss1 +ss2)

追问

还是一样报 右括号缺失 错误在是 s1后的,

追答

最后少了一个括号:
select ss1 +ss2 from(
(select sum(a*b) as ss1 from m , h
where type = 2 and m.code = h.code )s1,

(select sum(a*b) as ss2 from m , h1
where type = 2 and m.code = h1.code)s2) )

追问

还是那样的问题

追答

from 后面要有一个空格

追问

额(⊙o⊙)… 不行的

追答

那只能使用相关函数或者采用类似楼下的回答啦,你的oracle数据库吗?

追问

是oracle,谢谢了

追答

那方法就多啦,比如:
select
(elect sum(a*b) as ss1 from m , h
where type = 2 and m.code = h.code )+
(select sum(a*b) as ss2 from m , h1
where type = 2 and m.code = h1.code)s2)

from dual

本回答被提问者采纳
第2个回答  2019-02-26
SELECT ss1-ss2 FROM (SELECT SUM(s_money) AS ss1 FROM `shouqian`)s1,(SELECT SUM(f_money) AS ss2 FROM `faqian`)s2 就是两个查询语句查询相加减的两个表sum字段as命名 两个表查询命名 最后把这两个查询作为查询表去用sum的ss1-ss2 就可以了
第3个回答  2020-11-20

手机WPS表格中函数sum进行对数据求和,这样移动办公好

第4个回答  2011-04-07
select sum(a*b)
from m, h, h1
where typ2 = 2
and (m.code = h.code OR m.code = h1.code )
相似回答