I need to get last six month values from the database. Here is my Fiddle. I need to get the values dynamically. Now February. So I need August to Januar
SELECT
YEAR(DATE) AS YEAR,
SUM(MONTH(DATE) = 1) AS JAN ,
SUM(MONTH(DATE) = 2) AS FEB ,
SUM(MONTH(DATE) = 3) AS MAR ,
SUM(MONTH(DATE) = 4) AS APR,
SUM(MONTH(DATE) = 5) AS MAY ,
SUM(MONTH(DATE) = 6) AS JUNE ,
SUM(MONTH(DATE) = 7) AS JULY ,
SUM(MONTH(DATE) = 8) AS AUG,
SUM(MONTH(DATE) = 9) AS SEP ,
SUM(MONTH(DATE) = 10) AS OCTOBER ,
SUM(MONTH(DATE) = 11) AS NOV ,
SUM(MONTH(DATE) = 12) AS DECE
FROM ratepersqft
WHERE DATE >= NOW() - INTERVAL 6 MONTH
GROUP BY 1;