Subject | How to conditionally sum and count rows in Firebird? |
---|---|
Author | ezzodder@rocketmail.com |
Post date | 2011-02-14T16:58:11Z |
I've been using MySQL for years and I'm trying FB 2.5 to see how it
goes.
I'm stuck on creating the equivalent SQL in Firebird.
In MySQL I'd use:
SELECT SUM(IF(Amt>0,1,0)) AS Num_Pos, SUM(IF(Amt>0,Amt,0)) AS Pos_Owing,
SUM(IF(Amt<0,1,0)) AS Num_Neg, SUM(IF(Amt<0,Amt,0)) AS Neg_Owing FROM
TABLE1;
So I'd like to have 4 columns, the number of rows where Amt is positive
and the sum of the positive Amt, and the number of rows where Amt is
negative and the sum of the negative Amt.
I can't seem to get FB to do this in one SQL statement. Can someone
help?
TIA
Mike
goes.
I'm stuck on creating the equivalent SQL in Firebird.
In MySQL I'd use:
SELECT SUM(IF(Amt>0,1,0)) AS Num_Pos, SUM(IF(Amt>0,Amt,0)) AS Pos_Owing,
SUM(IF(Amt<0,1,0)) AS Num_Neg, SUM(IF(Amt<0,Amt,0)) AS Neg_Owing FROM
TABLE1;
So I'd like to have 4 columns, the number of rows where Amt is positive
and the sum of the positive Amt, and the number of rows where Amt is
negative and the sum of the negative Amt.
I can't seem to get FB to do this in one SQL statement. Can someone
help?
TIA
Mike