You might find the sql functions sum() and count() rather useful.
In reply to Re^2: Perform addition of data from rows by RichardK in thread Perform addition of data from rows by htmanning