paul_van_eeren has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks, Hoping on your help in this "puzzle" :) I'm trying to calculate a sum of the numbers, which i get from DB table. I have 3 fields: "id", "side" and "cost". Mysql query output is the following:
id side cost ------------ 1 | A | 120 2 | B | 90 3 | C | 110 4 | C | 100 5 | B | 140 6 | A | 50 7 | C | 160 8 | B | 120 9 | A | 110
from this output i'm trying to find a summary of 2 rows with `cost` field. In `side` field first row should be the B, and second one should be the one, which i going next in the output right after B.

eg. B = 90 and next from the row(C) = 110, so sum should be 200. then next B = 140, and next row(A) = 50. sum = 190 and last B = 120, A = 110. sum = 230.

If someone will help me with this, it will be really appreciated. Thanks in advance!

Replies are listed 'Best First'.
Re: summary of the numbers in some sequence
by AnomalousMonk (Archbishop) on Jun 21, 2011 at 22:55 UTC

    This sounds a bit like homework. How about showing a bit of your work first.

      Hi, This is not a homework, i do it for myself :) Anyway, i figured out how it should look. I used SQL query instead of perl syntax. Thanks anyway.
Re: summary of the numbers in some sequence
by toolic (Bishop) on Jun 22, 2011 at 00:35 UTC