mercredi 21 octobre 2015

Multiplying then summing the values over 2 tables

I have 2 tables. One called shopping, the other called products.

shopping has columns named Product, Number, Size and Units

my other table, products has the columns, Product, Price, Size and Units

I want to sum the total cost of the items bought on my shopping list taking into account the quantity of the items bought. To do this, I have firstly used the query:

SELECT shopping.Product, Number * Price
FROM products INNER JOIN
     shopping
     ON products.Product = shopping.Product;

To multiply the number of items bought * Price of the product.

I then wanted to add up the Number*Price total so I used:

SELECT shopping.Product, SUM (Number * Price)
FROM products INNER JOIN
     shopping
     ON products.Product = shopping.Product;

This does give the correct answer however, for some reason, it also outputs the 'Product' column and prints the name of one of my products, 'Milk' and includes it with the output. How can I get rid of this?

print screen: http://ift.tt/1M9yM4P

Aucun commentaire:

Enregistrer un commentaire