Loop through table, check name, and add total
I must be stupid today. I have a table with the same data which includes (among other things) company names and integer values. I need to pick one row, check for each time that name appears in the database, and add the integer value from that row to a total.
ex.
28469151 6398 80609 40032 CITY TREASURER
25404033 6289 041409CR 39926 CITY TREASURER
2408266 8473 071009开发者_JS百科 40017 CITY TREASURER
22332527 9710 2009 39975 THE ST JOE COMPANY
21570825 6857 051209CR 39954 CITY TREASURER
the program would add the number from row 2 every time it saw "city treasurer". any ideas? There are about 4000 records
Edit: I need to get the total for each company in the table.
I suppose that something like this (supposing that the first col is named col1)
select sum(col1) from table group by company;
SELECT SUM(`field1name`) FROM `table` GROUP BY `field2name`
精彩评论