title: SQL query to calculate value from two tables
body: <p>Hi
  I have two tables which are related in the following way :</p>
  
  <pre><code>Table1
  gene goterms
  ape   1a
  ape   1b
  ape   1c
  boy   2a
  boy   1a
  cat   1a
  cat   1c
  
  Table2
  gene gene count
  ape  ape   3
  ape  boy   1
  ape  cat   2
  boy  ape   1
  boy  boy   2
  boy  cat   1  
  cat  ape   2
  cat  boy   1
  cat  cat   2
  </code></pre>
  
  <p>now,i need value that corresponds to second row of table2 as
            = (count)/(count of ape from table 1 + count of boy from table 1) - count</p>
  
  <p>for [ape boy 1] row , value = 1 / ((3 + 2) - 1 ) = 0.25</p>
  
  <p>similarly for all the other rows in table2.</p>
  
  <p>The output must be like</p>
  
  <p>Table3
      gene gene count calc
      ape  ape   3     1
      ape  boy   1     .25
      ape  cat   2     .5
      boy  ape   1     .25
      boy  boy   2     1 
      boy  cat   1     .2 
      cat  ape   2     .5 
      cat  boy   1     .2 
      cat  cat   2      1</p>
  
  <p>I need a sql query for this , i attempted in many ways but in vain.</p>
  
  <p>Thank you...</p>