title: MySQL AVG function for recent 15 records by date (order date desc) in every symbol
body: <p>I am trying to create a statement in SQL (for a table which holds stock symbols and price on specified date) with avg of 5 day price and avg of 15 days price for each symbol.</p>
  
  <p>Table columns:</p>
  
  <ul>
  <li>symbol</li>
  <li>open</li>
  <li>high</li>
  <li>close</li>
  <li>date</li>
  </ul>
  
  <p>The average price is calculated from last 5 days and last 15 days. I tried this for getting 1 symbol:</p>
  
  <pre><code>SELECT avg(close),
         avg(`trd_qty`) 
    FROM (SELECT *
            FROM cashmarket 
           WHERE symbol = 'hdil'
           ORDER BY `M_day` desc 
           LIMIT 0,15 ) s
  </code></pre>
  
  <p>but I couldn't get the desired list for showing avg values for all symbols.</p>