- Millermy $last_id = ''; my $hrs_total; my $tips_total; foreach my $row (@$query) { if ($last_id ne $row->{id}) { $last_id = $row->{id}; $hrs_total = 0; $tips_total = 0; } $row->{beg_hr} = $hrs_total; $row->{end_hr} = $hrs_total += $row->{hrs}; $row->{beg_tip} = $tips_total; $row->{end_tip} = $tips_total += $row->{tips}; print join("\t", @{$row}{qw(dat code id cur beg_hr end_hr beg_tip +end_tip)}) . "\n"; }
In reply to Re: calculation using multiple rows of a query
by wind
in thread calculation using multiple rows of a query
by rocky13
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |