Fix some error in complex query