SELECT ... FROM your_table ORDER BY in, out; SELECT day, SUM(in + out) FROM your_table GROUP BY day;