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 > Database Server Software > Oracle > ORACLE Query Help

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-12-12, 21:59
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
ORACLE Query Help

I am using this query:
Code:
select category, '$'||sum(cost)AS "Total Retail" ,'$'||avg(cost) as "Average Retail" from books  group by category having sum(cost)>40;
I also tried this query and I got an ERROR of group function not allowed here:
Code:
select category, '$'|| sum(cost) as "Total Retail",'$'|| avg(cost) as "Average Retail" from books WHERE sum(cost)>40;
And this is returning 3 results....the correct query should return 4 results. Can someone point out where my error is?


****Disregard I was using the wrong field name for the sum/avg....Simple mistakes make life hell from time to time

Last edited by jo15765; 02-12-12 at 22:23.
Reply With Quote
  #2 (permalink)  
Old 02-13-12, 16:21
LKBrwn_DBA LKBrwn_DBA is offline
Registered User
 
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,456
Wink

Better use the TO_CHAR() function for formatting the amounts:
Code:
SELECT category
     , TO_CHAR(SUM( cost ),'$999,990.00') AS "Total Retail"
     , TO_CHAR(AVG( cost ),'$999,990.00') AS "Average Retail"
  FROM books
 GROUP BY category
HAVING SUM( cost ) > 40;
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
Reply With Quote
  #3 (permalink)  
Old 02-13-12, 16:45
jo15765 jo15765 is offline
Registered User
 
Join Date: Feb 2012
Posts: 20
Oh such a simple mistake! Thank you for your assistance
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