conditional select sum() based on field question
Posted in 1992
I have a question regarding selecting a sum from a table of amounts and depending upon the type of record, either adding or subtracting the amount from the sum. We are using Informix 4.0 ISQL and R4GL. I could do this in two select statements and the difference would be the net amount, but this requires that the data be read twice (once for each select statment). select sum(amount) into total_credits from orders where order_type = "CREDIT" select sum(amount) into total_normal_orders from orders where order_type = "REG" let net_amount = total_normal_orders - total_credits Is there a way that this could be done in one select statment?? Two select statments is no big deal for a small database, but this database contains hundreds of thousands of orders. If the data could be read only once it would pick up performance quite a bit. ============================================================================ Pete Frehner Voice (519) 673-3350 Praeda Management Systems Fax (519) 667-1968 371 Dufferin Ave. uucp: .....uunet!praeda!pfrehner London, Ontario CANADA N6B 1Z5