Aggregating database table cell values by similar cell values?
Nov 13, 2008 by Edwin M | Posted in Programming & Design
I have the following table in my MySQL database
id, company_id, model_id, amount
1, 2, 3, 7
2, 2, 5, 5
3, 2, 3, 1
What I want to do is sum the amounts where the company_id and model_id are the same. For
CV's answer whould work fine if you have no other criteria. If you do, then either WHERE or HAVING clauses (or both) can further refine the result. For example, if you only want to list sums resulting from multiple rows (in your example, for 2-3 but not
TheMadProfessor | Nov 14, 2008
The Absolute Best
by KenJ
favorite computer store: having preference = max(preference) market leading post-PC device: having market_share = max(market_share) largest annual sales bonus: having bonus = After making it through the checkout process and returning home, Bobby was pleased to discover that he could access his home network through the device. After making in through the most customer friendly checkout process and returning home in record time, Bobby was pleased to discover that this device had the easiest setup for accessing his home network....
Read more...