Results 1 to 5 of 5
  1. #1
    Join Date
    May 2004
    Location
    NH
    Posts
    87

    Cool Unanswered: Oracle SQL: Agg. Fn. Calculation

    Hi All,

    I don't know if it is possible but can you do something like this:

    Code:
    SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (calc1 - calc2) As Difference FROM ... WHERE ... GROUP BY ...
    Otherwise I'd have to do this:
    Code:
    SELECT Sum(columnX) As calc1, Sum(columnY) As calc2, (Sum(columnX) - Sum(columnY)) As Difference FROM ... WHERE ... GROUP BY ...
    So instead of calculating the sum twice, I have to do it four times... is there any way to improve this? I've searched everything I could and I found nothing (maybe I was using the wrong keywords, but I'm pretty sure I tried thme all!)

    Thanks in Advance!
    Warren

  2. #2
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Talking

    Oracle will do the SUM only once for each column and at the end do the calculations!
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

  3. #3
    Join Date
    May 2004
    Location
    NH
    Posts
    87
    See that's what I like to hear...!

    Where do I find info like that?

    Thank you!
    Anthony

  4. #4
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

  5. #5
    Join Date
    May 2004
    Location
    NH
    Posts
    87
    And I thank you...!

    Warren

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •