in reply to SQL Database Help!!
Loop through the result set and add them to a data structure indexed on the contents of the first column.
my %items; while (my ($item, $cost, $number, $value) = $sth->fetchrow_array()) { $items{ $item }{ cost } += $cost; $items{ $item }{ number } += $number; $items{ $item }{ value } += $value; }
Then just loop through the data structure and print appropriately.
You could also order the rows by the first column, keep a running tally in $cost, $number, and $value, and print a line when the first column changes.
|
|---|