skulk Posted July 29, 2007 Share Posted July 29, 2007 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 https://forums.phpfreaks.com/topic/62262-php-mysql-sortaggregate-problem/ Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 first off how do you have +/- as a category in a mysql table? using a bool type be much better, secondly you can sort your query by saying ORDER BY field Link to comment https://forums.phpfreaks.com/topic/62262-php-mysql-sortaggregate-problem/#findComment-309877 Share on other sites More sharing options...
skulk Posted July 29, 2007 Author Share Posted July 29, 2007 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 https://forums.phpfreaks.com/topic/62262-php-mysql-sortaggregate-problem/#findComment-309880 Share on other sites More sharing options...
cooldude832 Posted July 29, 2007 Share Posted July 29, 2007 I still don't get your table are you looking for a query like <?php $q = "Select * from table WHERE +/- != - ORDER BY Qty"; ?> Link to comment https://forums.phpfreaks.com/topic/62262-php-mysql-sortaggregate-problem/#findComment-309881 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.