in reply to Perform addition of data from rows
Let your database do it for you.
You might find the sql functions sum() and count() rather useful.