10 Replies - 690 Views - Last Post: 18 April 2017 - 02:12 PM Rate Topic: -----

#1 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

SQL help.

Posted 18 April 2017 - 01:09 PM

SO yes I am a student, but I need a little help. we are learning or have learned joined and I am trying to answer a question but could use some help.
the question is...

What is the total amount of money (TotalDue) spent on each order (orderID), and rounded the total by 2 decimal places?

we are using the database from this website...

https://www.w3school...ysql_func_round

this is what I have so far...

Select Products.ProductName, products.Price, ROUND (Price,2) products.ProductID, orders.OrderID, OrderDetail as totaldue
from products
Join Orders 
having totalDue;

:code:/>

I am running into errors but I am also really new to the SQL so if you could help me out I would appreciate it thank you!

Here is the Error I am getting. but I also feel I am missing some things.

Syntax error (missing operator) in query expression 'ROUND (Price,2) products.ProductID'.

This post has been edited by Lilith_Aries: 18 April 2017 - 01:14 PM
Reason for edit:: Please use the [code] button in the editor..


Is This A Good Question/Topic? 0
  • +

Replies To: SQL help.

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,898
  • Joined: 12-June 08

Re: SQL help.

Posted 18 April 2017 - 01:13 PM

Moving to the database area.

It also helps to copy/paste the errors here.

Major issues - looks like a comma is missing in the column listing.
JOINS need an "ON" to tell what columns in which table are being matched up.
Why is HAVING in there?
Was This Post Helpful? 0
  • +
  • -

#3 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

Re: SQL help.

Posted 18 April 2017 - 01:17 PM

Ok great thank you. I learned this last week and she has a really thick accent so its difficult to understand her. SO I have just been learning off of her examples mostly. Most of the time its enough but this time it was not. so thank you again.


Having is in there because that is how she had It in most of her examples. Wasn't sure why to be honest.

This post has been edited by Lilith_Aries: 18 April 2017 - 01:18 PM

Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,898
  • Joined: 12-June 08

Re: SQL help.

Posted 18 April 2017 - 01:19 PM

Please do not back edit your original post. Folk won't know what you changed or removed. Just post any update/additional info in the thread.
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is online

  • the case is sol-ved
  • member icon

Reputation: 6379
  • View blog
  • Posts: 25,774
  • Joined: 12-December 12

Re: SQL help.

Posted 18 April 2017 - 01:20 PM

Are you supplementing your classes with the w3schools tutorials? They are pretty good on SQL.

SQL Joins
Was This Post Helpful? 0
  • +
  • -

#6 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

Re: SQL help.

Posted 18 April 2017 - 01:25 PM

Yes, I would not have gotten this far in her class if I wasn't using it. There is a lot of info she give me that is lost in translation so I am trying to keep up. from what I hear tons of students have to take her classes 2x because they just cannot understand her. I am trying to avoid that..
Was This Post Helpful? 0
  • +
  • -

#7 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

Re: SQL help.

Posted 18 April 2017 - 01:39 PM

here is what I have now, no errors but I also have no results. I know that I need to add in OrderDetails but every way that I try its just not wanting to work. It will spit out more errors.

Select Products.ProductName, products.Price, ROUND (Price,2), products.ProductID, orders.OrderID as totaldue
from Products
Join Orders 
on products.ProductID=Orders.OrderID
order by price Desc


Was This Post Helpful? 0
  • +
  • -

#8 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,898
  • Joined: 12-June 08

Re: SQL help.

Posted 18 April 2017 - 01:43 PM

If you need the details in there perhaps join to the order details table.
Was This Post Helpful? 0
  • +
  • -

#9 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

Re: SQL help.

Posted 18 April 2017 - 01:55 PM

Ok thank you so much for your help, her wording in the question threw me off because when she put " each order (orderID), " Thought she wanted the order table. But I fixed it. LMK what you all think.

Select Products.ProductName, products.Price, ROUND (Price,2), products.ProductID, orderDetails.OrderID, orderdetails.ProductID, OrderDetails.Quantity as totaldue
from Products
Join OrderDetails
on products.ProductID=Orderdetails.ProductID
order by price Desc


Was This Post Helpful? 0
  • +
  • -

#10 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13493
  • View blog
  • Posts: 53,898
  • Joined: 12-June 08

Re: SQL help.

Posted 18 April 2017 - 02:01 PM

Personally I would use a subquery that gets the order id and 'quantity * price' using joins. The parent query would use the aggregate 'SUM' on the 'quantity * price' column.. grouping by the order id.
Was This Post Helpful? 0
  • +
  • -

#11 Lilith_Aries  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 70
  • Joined: 06-September 15

Re: SQL help.

Posted 18 April 2017 - 02:12 PM

not sure we have learned that could you give me an example?
NOT the answer (I have that now) just an example to look at?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1