title: MySQL rank by value for each day
body: <p>I am attempting to rank by % return for each day across 700 symbols.</p>
  
  <p>For Example:</p>
  
  <pre><code>date     symbol    pct_return
  -----------------------------
  1100101  IBM       1.2
  1100101  AAPL      2.1
  1100101  HPQ       -0.5
  </code></pre>
  
  <p>approx 700 more entries like this for date 1100101</p>
  
  <pre><code>1100102  IBM       -.02
  1100102  AAPL      -.6
  1100102  HPQ       1.9
  </code></pre>
  
  <p>approx 700 more entries like this for date 1100102</p>
  
  <p>What I am trying to do is create a query or stored procedure to loop through each day, and then rank and insert the rank value for the percent return for each symbol within each day. </p>
  
  <p>I would like to insert the rank values for both ascending and descending ranking of percent return. </p>
  
  <p>Sample table for just 3 symbols after ranking would look like:</p>
  
  <pre><code>date     symbol    pct_return    rank_asc   rank_desc
  ------------------------------------------------------
  1100101  IBM       1.2             2         2
  1100101  AAPL      2.1             3         1
  1100101  HPQ       -0.5            1         3
  1100102  IBM       -.02            2         2
  1100102  AAPL      -.6             1         3
  1100102  HPQ       1.9             3         1
  </code></pre>