永发信息网

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

答案:3  悬赏:40  手机版
解决时间 2021-11-25 18:40
  • 提问者网友:抽煙菂渘情少年
  • 2021-11-25 02:06
sql中怎么将两个做了sum之后的值相加
最佳答案
  • 五星知识达人网友:野慌
  • 2021-11-25 03:09
最简单的方法:
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
全部回答
  • 1楼网友:拜訪者
  • 2021-11-25 04:39
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后面没有括号
  • 2楼网友:你可爱的野爹
  • 2021-11-25 03:44
select sum(a*b)
from m, h, h1
where typ2 = 2
and (m.code = h.code OR m.code = h1.code )
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯