title: mysql - Calculate Percentage from two different table
body: <p>I have two tables, and i want to get the percentage value and update the percentage to the table. Suppose we have two table like this,</p>
  
  <p><strong>Table 1</strong></p>
  
  <pre><code>   date     open   high   low   close   stock_id
  2013-01-02   10     20     5     15        1
  2013-01-02   150    200   100    170       2
  2013-01-03   15     30     10    20        1
  </code></pre>
  
  <p><strong>Table 2</strong></p>
  
  <pre><code>   date     p_high  p_low   percent   stock_id
  2013-01-02   25     10       0.00        1
  2013-01-02   210    120      0.00        2
  2013-01-03   40     20       0.00        1
  </code></pre>
  
  <p>I want to calculate the percentage using this formula</p>
  
  <pre><code>(p_high - high) / high
  </code></pre>
  
  <p>Percentage for <code>stock_id = 1</code> in <code>date = 2013-01-02</code> will be like this.</p>
  
  <pre><code>(25 - 20) / 20 = 25.00
  </code></pre>
  
  <p>When i get the percentage, i want to update it to <strong>Table 2</strong> so it will be like this,</p>
  
  <pre><code>  date      p_high   p_low   percent   stock_id
  2013-01-02    25      10      25.00       1
  </code></pre>
  
  <p>How can i do that in mysql?</p>
  
  <p>Thank you for your help.</p>