Fix aggregates query