title: Finding Covariance using SQL
body: <pre><code># dt---------indx_nm1-----indx_val1-------indx_nm2------indx_val2
  2009-06-08----ABQI------1001.2------------ACNACTR----------300.05
  2009-06-09----ABQI------1002.12 ----------ACNACTR----------341.19
  2009-06-10----ABQI------1011.4------------ACNACTR----------382.93
  2009-06-11----ABQI------1015.43 ----------ACNACTR----------362.63
  </code></pre>
  
  <p>I have a table that looks like ^  (but with hundreds of rows that dates from 2009 to 2013). Is there a way that I could calculate the covariance : [(<code>indx_val1</code> - avg(<code>indx_val1</code>)) * (<code>indx_val2</code> - avg(<code>indx_val2</code>)] divided by total number of rows for each value of <code>indx_val1</code> and <code>indx_val2</code> (loop through the entire table) and return just a simple value for cov(<code>ABQI</code>, <code>ACNACTR</code>)</p>