Home > Software engineering >  SQL: Finding the Average per month
SQL: Finding the Average per month

Time:12-29

I have 2 columns. DATE and DFF (it is a FLOAT for a interest rate. I need to get the average interest rate for every month. EXAMPLE: DATE DFF 2003-01-04 2.0 2003-01-18 2.25 2003-01-25 2.5 2003-02-08 3.0 2003-02-15 3.25 2003-02-27 2.75 2004-05-07 4.0 2004-05-25 4.0

Outcome I am looking for is... EXAMPLE: date avg_dff 2003-01 2.25 2003-02 3.0 2004-05 4.0

CodePudding user response:

Could you please check if this query solves your problem:

SELECT DATE_FORMAT(DATE, '%Y-%m') AS date, AVG(DFF) AS dff FROM your_table GROUP BY DATE_FORMAT(DATE, '%Y-%m')

  • Related