Jump to content

PHP-MySQL sort/aggregate problem


skulk

Recommended Posts

I want to accomplish the following, either through php or mysql queries, not had much luck in the last few days, so if anyone could help me, ....

I have:

Desc  | +/- | Qty

A        | +  | 10

A        | +  | 10

A        | -  | 20

A        | +  | 5

B        | +  | 2

A        | +  | 3

 

I want the final output to be:

Desc  | +/- | Qty

A        | +  | 8

B        | +  | 2

 

Basically go through the table, and if something has been bought and sold completely, ignore that 'desc'. If not just display the final holding after all +'s and -'s. The first table will be in a mysql table, and the +/- will be 'B'/'S'.

Thanks alot

 

edit .... the 'Desc' is not limited to A and B, it could be as few as 2 variables and as many as 300.

Link to comment
Share on other sites

It won't be +/- as I mentioned in the last line, it will be B/S. My mysql knowledge is really limited, so I found code for sorting in PHP (which I guess is longer than what you said), but the 2nd part, summing it up etc, I couldn't figure out.

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.