Jump to content

Recommended Posts

Really not sure what to call this, but lets assume we have this table called "InventoryTable"

--------------------------------------
| Item                      | Weight |
--------------------------------------
| Red Striped Wallpaper     | 125    |
| Green Striped Wallpaper   | 150    |
--------------------------------------

 

 

Then we have another table called "AmountLeft"

 

--------------------------------------
| Item                      | Qnty   |
--------------------------------------
| Red Striped Wallpaper     | 3      |
| Green Striped Wallpaper   | 4      |
--------------------------------------

 

What I want to ultimately do is return the total weight (which would be 3*125 + 4*150 = 975) based on the quantity of the item times the weight from the other table. Is there some way to get sum() to do calculations to multiple the weight by the quantity of each row?

Link to comment
https://forums.phpfreaks.com/topic/224395-return-sum-by-quantity/
Share on other sites

Yes. The second table is how much each user has left (i neglected some fields, like user id etc, to make it easier to read)

 

EX user A has 3 Red Striped Wallpaper and 4 Green Striped Wallpaper and a total of 1000 storage space, so I wanted to total up the amount quicker than my current way of using php to do it.

so youre looking for something like

SELECT SUM (inventoryTable.weight * AmountLeft.qnty) FROM AmountLeft INNER JOIN inventoryTable ON (amountLeft.Item = inventoryTable.Item) WHERE USER ID = <some id number>

Not that I think that will work, but does it look like what you want to do?

 

Could you also provide the full tables, as knowing all the filds and their relations makes things easier than just knowing what is apparently relevant.

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.