title: How does the Average function work in relational databases?
body: <p>I'm trying to find geometric average of values from a table with millions of rows.  For those that don't know, to find the geometric average, you mulitply each value times each other then divide by the number of rows.</p>
  
  <p>You probably already see the problem;  The number multiplied number will quickly exceed the maximum allowed system maximum. I found a great solution that uses the natural log.</p>
  
  <p><a href="http://timothychenallen.blogspot.com/2006/03/sql-calculating-geometric-mean-geomean.html" rel="nofollow">http://timothychenallen.blogspot.com/2006/03/sql-calculating-geometric-mean-geomean.html</a></p>
  
  <p>However that got me to wonder wouldn't the same problem apply with the arithmetic mean?  If you have N records, and N is very large the running sum can also exceed the system maximum.</p>
  
  <p>So how do RDMS calculate averages during queries?</p>