-3

View material_master table here

I would like to retrieve the material_price and quantity from material_master table (refer to picture), after which I want to multiply and add the cost together.

Example:

(For Table Top) --> 10*1=10 

(For Legs) --> 4*4=16

 Total = 10+4=$26.

How do I execute it in query?

Mark Amery
  • 143,130
  • 81
  • 406
  • 459
Janice
  • 57
  • 1
  • 7

1 Answers1

-1

Try This:

SELECT SUM(material_price*quantity) as TotalPrice, 
material_price_master_id,
material_name 
FROM material_master 
GROUP BY material_price_master_id

It will also work without using SUM function as well

devpro
  • 16,184
  • 3
  • 27
  • 38
  • Is the way to echo the result? Total Material Cost =

    – Janice Dec 23 '15 at 05:48
  • @Janice: you are going right, just little changes required for reference please check.http://www.w3schools.com/php/func_mysqli_free_result.asp – devpro Dec 23 '15 at 06:13
  • @Janice: if you still face an issue let me know, and one more thing, i think you are new on SO, kindly accept the best answer by using left green tick. this will help full for others. – devpro Dec 23 '15 at 06:16
  • Hi, I have another question. I would like to echo the quantity for table top and legs respectively. right now this is my code which only echo the number 1. `

    Total quantity of Table Tops:

    Total quantity of Table Legs:

    ` How do I echo for Table Top should be 1, Legs should be 4?
    – Janice Jan 05 '16 at 07:17