Subject Re: [firebird-support] adding positive and negative values in differents columns
Author Milan Babuskov
Sergio H. Gonzalez wrote:
> Something wrong with my question? probably in not too clear... All I'd like to
> know if this is the *best* way of slpitting a sum column in two

Well, I don't know if it's the *best*, but it looks ok to me.

>> SELECT
>> D.id,
>> Sum(case when D.importe > 0
>> then D.importe
>> else 0 end) as positive,
>> Sum(case when D.importe < 0
>> then Abs(D.importe)
>> else 0 end) as negative

Instead of ABS, you can also use minus:

sum(case when d.importe < 0 then -d.importe else 0 end


>> FROM MyTable D
>> GROUP BY D.id
>> ORDER BY D.id

--
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com