Mysql Avg function for recent 15 records by date (order date desc) in every symbol

Posted by venkatesh on Stack Overflow See other posts from Stack Overflow or by venkatesh
Published on 2010-01-02T08:27:24Z Indexed on 2010/05/08 9:08 UTC
Read the original article Hit count: 218

Filed under:
|

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.

table description:

  • symbol
  • open
  • high
  • close
  • date

the average price is calculated from last 5 days and last 15 days. i tried this for getting 1 symbol:

SELECT avg(close),
       avg(`trd_qty`) 
  FROM (select *
          from cashmarket 
         WHERE symbol = \'hdil\' 
      order by `M_day` desc 
          limit 0,15 ) s

...but I couldn't get the desired the list for showing avg values for all symbols.

© Stack Overflow or respective owner

Related posts about mysql-query

Related posts about sql