Jump to content

Some tricky database calculating - i think :p


JJohnsenDK

Recommended Posts

Hey

 

Im trying to find the highest amount for products in my stock and i want to find it by products_id and color_no.

 

By that i mean that one product can have many different colors so i want to sort the amount of products after which color they have.

 

Here is my database:

 

stock_id      - 1

products_id - 3

color_no    - 55555

units_in      - 20

units_out    - 0

date          - 15/10-07

 

stock_id      - 2

products_id - 3

color_no    - 66666

units_in      - 10

units_out    - 0

date          - 15/10-07

 

stock_id      - 3

products_id - 3

color_no    - 55555

units_in      - 0

units_out    - 5

date          - 15/10-07

 

stock_id      - 4

products_id - 3

color_no    - 66666

units_in      - 0

units_out    - 5

date          - 15/10-07

 

So here i got 4 actions in my database. I have recived 10 items of products 3 with the color no 66666 and 20 items of product 3 with the color_no 55555 and then later sold 5 items of the product with color no 66666. Later i sell 5 items of the same product but this product have the color no 55555.

 

This gives me a total of 5 items with the color no 66666 and 15 items with the color no 55555 at my stock.

 

How do i add this up and only echo out the item with the highest amout of items?

 

 

 

Link to comment
Share on other sites

yeah... i know of these functions but i dont think i can use them? because i have the units_in and units_out colums.

 

And i cant multiply this in the mysql query like this:

 

mysql_query("SELECT SUM(units_in) AS units_in, SUM(units_out) AS units_out FROM stock WHERE products_id = '$product' and color_no = '$color'");

 

this would only give me the sum of units_in and units_out for one of the products.

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.