Any thoughts/advice very appreciated.
Don't optimize prematurely. :-)
Seriously, summing ~10K rows from a database using a while/+= combo takes fractions of a second on my 1.8GHz ... plenty 'quick' for me.
As for a MySQL solution, see SUM().
--k.
| [reply] |
Kanji is absolutly right you are looking for the SUM() function. You should also learn about all your other aggregate SQL functions.
grep
|
Unix - where you can throw the manual on the keyboard and get a command |
| [reply] |
SELECT category, SUM(fee) FROM tblproducts WHERE category like 'Phorno
+';
That should be it. Since SUM is a grouping func, you need to apply all grouping rules to the selects you plan. Hence be sure the SUM set returns an unique index (for example the CATEGORY here, for which is made a subset).
Without the WHERE, I'd have as much rows in the resulting recordset as there are CATEGORIES in the table.
Hope I made myself clear. :) | [reply] [d/l] |
Your SQL is incorrect since there is no "group by" expression used in conjuction with the aggregate function:
SELECT category,
SUM(fee)
FROM tblproducts
/* optional where clause */
GROUP BY category
would be correct.rdfield
| [reply] [d/l] |