changed query aggregate function