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
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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.