Trouble with querying in Oracle using SQL

Reply

Join Date: Feb 2009
Posts: 18
Reputation: danielle23 is an unknown quantity at this point 
Solved Threads: 0
danielle23 danielle23 is offline Offline
Newbie Poster

Trouble with querying in Oracle using SQL

 
0
  #1
Oct 7th, 2009
I am working on an Oracle homework assignment, working in shell, trying to query a tricky display question my professor has asked for. I will show both tables, and what I have to execute.

  1. SQL> describe orderline
  2. Name NULL? TYPE
  3. ----------------------------------------- -------- ----------------------------
  4. LINENUM NOT NULL NUMBER(3)
  5. ORDERNUM NOT NULL CHAR(4)
  6. ITEMID CHAR(3)
  7. QUANTITY NUMBER(4)
  8.  
  9. SQL> SELECT * FROM orderline;
  10.  
  11. LINENUM ORDE ITE QUANTITY
  12. ---------- ---- --- ----------
  13. 1 P111 B57 10
  14. 3 P100 B53 1
  15. 2 P100 B57 3
  16. 2 P105 C91 1
  17. 2 P111 X41 3
  18. 1 P109 C91 4
  19. 1 P100 X41 5
  20. 1 P105 B57 10
  21.  
  22. 8 ROWS selected.
  23.  
  24. SQL> describe stockitem
  25. Name NULL? TYPE
  26. ----------------------------------------- -------- ----------------------------
  27. ITEMID NOT NULL CHAR(3)
  28. ITEMNAME CHAR(8)
  29. ITEMPRICE NUMBER(5,2)
  30.  
  31. SQL> r
  32. 1 SELECT * FROM orderline;
  33.  
  34. LINENUM ORDE ITE QUANTITY
  35. ---------- ---- --- ----------
  36. 1 P111 B57 10
  37. 3 P100 B53 1
  38. 2 P100 B57 3
  39. 2 P105 C91 1
  40. 2 P111 X41 3
  41. 1 P109 C91 4
  42. 1 P100 X41 5
  43. 1 P105 B57 10
  44.  
  45. 8 ROWS selected.

The question on the homework reads: Write a query that will display the total cost of order P105 (answer is 79.65)

I wrote this code:
  1. SQL> r
  2. 1 SELECT ordernum, SUM(itemprice*quantity)
  3. 2 AS totalcost
  4. 3 FROM orderline,stockitem
  5. 4 WHERE orderline.itemid = stockitem.itemid
  6. 5* AND ordernum = 'P105';

I am receiving this error:
ERROR at line 1:
ORA-00937: not a single-group group function

I am stumped. I have tried numerous versions of this code, but this one in particular makes the most sense to me. Please help me if what is wrong here seems to jump out at you!!

Thank you....
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,132
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic
 
0
  #2
Oct 8th, 2009
Sorry, we do not solve home works /assignments here.

The error message is self explanatory.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Feb 2009
Posts: 18
Reputation: danielle23 is an unknown quantity at this point 
Solved Threads: 0
danielle23 danielle23 is offline Offline
Newbie Poster
 
0
  #3
Oct 8th, 2009
Actually, I believe that it is within the rules that if you show that you've done the work, and still having trouble with the syntax, people are certainly able to assist the person in need. This is not the first time I have come here for help and received just the push I needed to solve my problem. After all, isn't that what these forums are for?

I certainly was not asking anyone to do the work for me, as I clearly have my own attempted code placed here.

All that aside though, I did in fact figure it out in the end. Thanks anyway.
Reply With Quote Quick reply to this message  
Join Date: Feb 2007
Posts: 2,132
Reputation: debasisdas will become famous soon enough debasisdas will become famous soon enough 
Solved Threads: 132
debasisdas's Avatar
debasisdas debasisdas is offline Offline
Postaholic
 
0
  #4
Oct 9th, 2009
Just try adding a GROUP BY statement to your existing query.
Share your Knowledge.
Reply With Quote Quick reply to this message  
Join Date: Oct 2009
Posts: 10
Reputation: Drlionheart is an unknown quantity at this point 
Solved Threads: 1
Drlionheart Drlionheart is offline Offline
Newbie Poster
 
0
  #5
Oct 13th, 2009
Hello
for every summary column in sql , you have to use 'GROUP BY' condition

Now u try this query surely it will run


  1. SELECT ordernum, SUM(itemprice*quantity)
  2. AS totalcost FROM orderline,stockitem
  3. WHERE orderline.itemid = stockitem.itemid
  4. AND ordernum = 'P105'
  5. GROUP BY ordernum;
Last edited by peter_budo; Oct 13th, 2009 at 1:46 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks).
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



Tag cloud for Oracle
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC