update query to correct aggregate issues