I have 2 select queries against the same table which both contain only a sum()
inside the select part, but differ in the where
clause. What I need to do, is to sum the result of both the queries.
Example queries:
SELECT SUM(amount)
FROM EXAMPLETABLE
WHERE IDATE BETWEEN '2017/01/01' AND '2017/12/31' AND SOMESTATUS = 0
SELECT SUM(otherAmount)
FROM EXAMPLETABLE
WHERE IDATE BETWEEN '2018/01/01' AND '2018/12/31' AND SOMESTATUS = 1
What I need is something like
SELECT SUM(amount+otherAmount)
FROM EXAMPLETABLE
where amount
and otherAmount
are selected as in my example queries.
I tried to follow this question, but I couldn't get it to work. I also tried to replace the fields with a sub-select
, but this doesn't work, because selects
are not allowe inside an aggregate function