Make sure having clause uses selected fields