sql - On a single column : Algebraic operation on Aggregate functions -
is possible on same sql select query (no function/procedure nor pl/sql) compute algebraic operation on 2 aggregate functions ?
| id || | |-----||-----| | 1 || 10 | | 2 || 20 | | 3 || 30 | | 4 || 40 | select (select sum(a) table 'id even') - (select sum(a) table 'id odd') table 'condition'
any idea ?
ps : databse oracle 11g
you can this:
select sum(case when mod(id,2)=0 else 0 end) - sum(case when mod(id,2)=0 0 else end) test yourcondition
the sqlfiddle mysql sample, since oracle have mod
function should work is.
see working here: http://sqlfiddle.com/#!9/1ba756/2
Comments
Post a Comment