Subject | Re: [firebird-support] adding positive and negative values in differents columns |
---|---|
Author | Milan Babuskov |
Post date | 2009-04-14T12:48:52Z |
Sergio H. Gonzalez wrote:
sum(case when d.importe < 0 then -d.importe else 0 end
Milan Babuskov
http://www.flamerobin.org
http://www.guacosoft.com
> Something wrong with my question? probably in not too clear... All I'd like toWell, I don't know if it's the *best*, but it looks ok to me.
> know if this is the *best* way of slpitting a sum column in two
>> SELECTInstead of ABS, you can also use minus:
>> 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
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