| | |
Trouble with querying in Oracle using SQL
Please support our Oracle advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2009
Posts: 18
Reputation:
Solved Threads: 0
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.
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:
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....
Oracle Syntax (Toggle Plain Text)
SQL> describe orderline Name NULL? TYPE ----------------------------------------- -------- ---------------------------- LINENUM NOT NULL NUMBER(3) ORDERNUM NOT NULL CHAR(4) ITEMID CHAR(3) QUANTITY NUMBER(4) SQL> SELECT * FROM orderline; LINENUM ORDE ITE QUANTITY ---------- ---- --- ---------- 1 P111 B57 10 3 P100 B53 1 2 P100 B57 3 2 P105 C91 1 2 P111 X41 3 1 P109 C91 4 1 P100 X41 5 1 P105 B57 10 8 ROWS selected. SQL> describe stockitem Name NULL? TYPE ----------------------------------------- -------- ---------------------------- ITEMID NOT NULL CHAR(3) ITEMNAME CHAR(8) ITEMPRICE NUMBER(5,2) SQL> r 1 SELECT * FROM orderline; LINENUM ORDE ITE QUANTITY ---------- ---- --- ---------- 1 P111 B57 10 3 P100 B53 1 2 P100 B57 3 2 P105 C91 1 2 P111 X41 3 1 P109 C91 4 1 P100 X41 5 1 P105 B57 10 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)
SQL> r 1 SELECT ordernum, SUM(itemprice*quantity) 2 AS totalcost 3 FROM orderline,stockitem 4 WHERE orderline.itemid = stockitem.itemid 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....
•
•
Join Date: Feb 2009
Posts: 18
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Oct 2009
Posts: 10
Reputation:
Solved Threads: 1
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
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)
SELECT ordernum, SUM(itemprice*quantity) AS totalcost FROM orderline,stockitem WHERE orderline.itemid = stockitem.itemid AND ordernum = 'P105' 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).
![]() |
Similar Threads
- Console Application : Oracle to SQL (VB.NET)
- Oracle Sql (Oracle)
- let me know d steps to connect to oracle(sql) from vb6 (Visual Basic 4 / 5 / 6)
- Oracle sql developer question (Oracle)
- i have installed oracle 9i sql but while installing forms & reports it gives errors t (Oracle)
- oracle or sql server2000, which is best? (Oracle)
Other Threads in the Oracle Forum
- Previous Thread: which language google made in
- Next Thread: subtract 2 column value
| Thread Tools | Search this Thread |
2009predictions acquisition amazon.com bartz bernanke cia citrix cloudcomputing crm database dell economy editor enterprise enterprise2.0 enterprisesoftware federalreserve forbes hp ibm intellipedia internet larryellison layoffs linux loughridge mediawiki michaeljackson microsoft neverland nortel notebooks oil operatingsystem oracle palm rimm saas salesforce sap seagate socialcomputing sql sun sybase technologystocks virtualiron virtualization vmware wiki wikipedia xen yahoo zoho






