SELECT year, sum( if( month = 1, amount, 0 ) ) AS m1, sum( if( month = 2, amount, 0 ) ) AS m2, sum( if( month = 3, amount, 0 ) ) AS m3, sum( if( month = 4, amount, 0 ) ) AS m4 FROM statistics GROUP BY year;