Fix query group by year and month to work well with postgre