Jump to content

[SOLVED] multiply 2 columns and add them


guyfromfl

Recommended Posts

ok lets say I have a table

 

--------------------------------
| id  | invoiceId |  qty  |  price  |
--------------------------------
|1    | 10354     | 2      | 5       |
|2    | 10356     | 3      | 6       |
|3    | 10354     | 4      | 1       |
--------------------------------

 

I want to multiply qty * price where invoiceId=10354 then add the sum of each.

 

would it be better to just add a total column? or is there a sql function that i could use?

 

thanks

Link to comment
https://forums.phpfreaks.com/topic/175070-solved-multiply-2-columns-and-add-them/
Share on other sites

Yea im making an invoice system in php.

 

I have 2 tables parts.invoice (customer data record of the invoice....this has a total field)

and  parts.invoiceitems (individual things a customer buys.)

 

so if I add a new item after the invoice is generated, I want to have a new total to put in parts.invoice.total.

 

and when I add an item to the order, I have to update the invoice total.

 

I have php creating the subtotals for the invoice, but I was tinkering with the idea of doing it all on the database.

 

Any suggestions?

basically multiply qty and price from row 1, then mulitply qty and price from row 3 then add it together.

 

My script is already doing it in php, I just wanted to see how it works if I get it from the db and leave it all in the mysql database.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.