home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / database / informix / 1701 next >
Encoding:
Internet Message Format  |  1992-08-12  |  1.5 KB

  1. Path: sparky!uunet!praeda.UUCP!pete
  2. From: pete@praeda.UUCP.UUCP (Pete Frehner)
  3. Newsgroups: comp.databases.informix
  4. Subject: conditional select sum() based on field question
  5. Keywords: select sum
  6. Message-ID: <297@praeda.UUCP.UUCP>
  7. Date: 12 Aug 92 15:55:47 GMT
  8. Organization: Praeda Management Systems, Inc.
  9. Lines: 29
  10.  
  11.  
  12. I have a question regarding selecting a sum from a table of amounts and
  13. depending upon the type of record, either adding or subtracting the amount
  14. from the sum.  We are using Informix 4.0 ISQL and R4GL.
  15.  
  16. I could do this in two select statements and the difference would be the
  17. net amount, but this requires that the data be read twice (once for each
  18. select statment).  
  19.  
  20.  
  21.    select sum(amount) into total_credits
  22.        from orders where order_type = "CREDIT"
  23.  
  24.    select sum(amount) into total_normal_orders 
  25.        from orders where order_type = "REG"
  26.  
  27.    let net_amount = total_normal_orders - total_credits 
  28.  
  29.  
  30. Is there a way that this could be done in one select statment??  Two select
  31. statments is no big deal for a small database, but this database contains
  32. hundreds of thousands of orders.  If the data could be read only once it would
  33. pick up performance quite a bit.
  34.  
  35. ============================================================================
  36. Pete Frehner                 Voice (519) 673-3350
  37. Praeda Management Systems                Fax   (519) 667-1968
  38. 371 Dufferin Ave.                        uucp: .....uunet!praeda!pfrehner
  39. London, Ontario CANADA N6B 1Z5           
  40.