fix pivot query for processing