我试图在两个不同的条件下获取相同变量的总和。只是想知道是否有办法将它们加在一起。查询的细节并不是很相关。基本上只是尝试将第一个和与第二个和相加。
例如 -
首先查询:
select sum(amt_tot)
from agbgift, aprdclb
where agbgift_id = '1' and agbgift_id = aprdclb_id
Run Code Online (Sandbox Code Playgroud)
第二个查询:
select sum(amt_tot)
from agbgift, aprxref, aprdclb where
aprxref_id = '1' and
agbgift_id = aprxref_xref_id and
aprxref_id = aprdclb_id and
xref_code in ('SPS','BUS','ORG','OWN','FDN' );
Run Code Online (Sandbox Code Playgroud)
我正在寻找的最终结果是“第一查询总和” +“第二查询总和”
在这种情况下,就这么简单:
SELECT
/* Query 1 (in parentheses) */
(select sum(amt_tot)
from agbgift, aprdclb
where agbgift_id = '1' and agbgift_id = aprdclb_id)
+ /* plus */
/* Query 2 (also in parentheses) */
(select sum(amt_tot)
from agbgift, aprxref, aprdclb where
aprxref_id = '1' and
agbgift_id = aprxref_xref_id and
aprxref_id = aprdclb_id and
xref_code in ('SPS','BUS','ORG','OWN','FDN' ))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3862 次 |
| 最近记录: |