944,116 Members | Top Members by Rank

Ad:
  • Oracle Discussion Thread
  • Unsolved
  • Views: 1319
  • Oracle RSS
Oct 7th, 2009
0

Trouble with querying in Oracle using SQL

Expand Post »
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.

Oracle Syntax (Toggle Plain Text)
  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:
Oracle Syntax (Toggle Plain Text)
  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....
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danielle23 is offline Offline
20 posts
since Feb 2009
Oct 8th, 2009
0
Re: Trouble with querying in Oracle using SQL
Sorry, we do not solve home works /assignments here.

The error message is self explanatory.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Oct 8th, 2009
0
Re: Trouble with querying in Oracle using SQL
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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
danielle23 is offline Offline
20 posts
since Feb 2009
Oct 9th, 2009
0
Re: Trouble with querying in Oracle using SQL
Just try adding a GROUP BY statement to your existing query.
Featured Poster
Reputation Points: 665
Solved Threads: 427
Posting Genius
debasisdas is offline Offline
6,406 posts
since Feb 2007
Oct 13th, 2009
0
Re: Trouble with querying in Oracle using SQL
Hello
for every summary column in sql , you have to use 'GROUP BY' condition

Now u try this query surely it will run


sql Syntax (Toggle Plain Text)
  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).
Reputation Points: 10
Solved Threads: 1
Newbie Poster
Drlionheart is offline Offline
10 posts
since Oct 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Oracle Forum Timeline: which language google made in
Next Thread in Oracle Forum Timeline: subtract 2 column value





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC