Kenny Ellis Kenny Ellis - 2 months ago 18
MySQL Question

Beginner SQL database manipulation

I am brand spankin new to SQL, I was trying to complete this little objective, however I keep getting... Empty set (0.00 sec)

Task:



1) List all the items with their extended price (quantity * price)

2) List the total cost of all the items in the store

My input:



mysql> select * from store where price = Qty*Price;

what I believe I have said is... select ALL from "store" where my new updated price is now equal to the Qty*Price..

Which gets me...



Empty set (0.00 sec)

Heres my code for "store".



INSERT INTO
store
(
Id
,
Name
,
Qty
,
Price
) VALUES

(1, 'apple', 10, 1),

(2, 'pear', 5, 2),

(3, 'banana', 10, 1.5),

(6, 'lemon', 100, 0.1),

(5, 'orange', 50, 0.2);

Can anyone help as to why this is happening??

Thank you!

Answer

1) List all the items with their extended price (quantity * price):

SELECT Qty*Price as extended_price FROM store

2) List the total cost of all the items in the store:

SELECT SUM(Qty*Price) as total_cost FROM store