Fixed sql query grouping, enabled aggregation for monthly view