Group by month and year in MySQL Group by month and year in MySQL mysql mysql

Group by month and year in MySQL


GROUP BY YEAR(t.summaryDateTime), MONTH(t.summaryDateTime);

is what you want.


GROUP BY DATE_FORMAT(summaryDateTime,'%Y-%m')


I prefer

SELECT    MONTHNAME(t.summaryDateTime) as month, YEAR(t.summaryDateTime) as yearFROM    trading_summary t GROUP BY EXTRACT(YEAR_MONTH FROM t.summaryDateTime);