Write SQL with HAVING and efficient joins | Meta SQL Question