in reply to calculate all the data

if the only thing you are doing with the data from your SQL query is calculating the sum, you could use the database's sum function for a much more efficient result.