If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Oracle SQL: Agg. Fn. Calculation

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-29-04, 08:02
WarrenM WarrenM is offline
Registered User
 
Join Date: May 2004
Location: NH
Posts: 87
Cool 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
Reply With Quote
  #2 (permalink)  
Old 06-29-04, 08:40
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
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
Reply With Quote
  #3 (permalink)  
Old 06-29-04, 08:41
WarrenM WarrenM is offline
Registered User
 
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
Reply With Quote
  #4 (permalink)  
Old 06-29-04, 08:51
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
Question

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #5 (permalink)  
Old 06-29-04, 08:53
WarrenM WarrenM is offline
Registered User
 
Join Date: May 2004
Location: NH
Posts: 87
And I thank you...!

Warren
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On