SELECT YEAR(timestamp) as year, SUM( IF(direction=1, bytes, 0) ) as Upload, SUM( IF(direction=2, bytes, 0) ) as Download, SUM( bytes ) FROM table GROUP BY year