title: Best way to take the SQL SUM of a large data set in a distributed environement
body: <p>Problem Scenario</p>
  
  <p>Consider a database design for a super market. I have a two tables(A &amp; B) to store the records of adding Items(A) to the inventory and to record sales(B). In order to get the running balance of a particular item in the shop, I have to take the sum of items from A and subtract sum of that particular items from B. Please consider this as the abstract scenario.</p>
  
  <p>Assume that the number of rows in each table is very high.</p>
  
  <p>My problem is what is the best practice to calculate the running balance in this case. Is it OK to write a SQL to do exactly what I mentioned above or is there any other performance wise and resources wise friendly methodology. I can't calculate the running balance real time since I am running this in a distributed environment. (using symmtericds). Hence in my case multiple stores adds records to their local databases and Symmetricds update those records in a master database.(Cloud) . How ever balance query will be always executed at the Master database.</p>