title: Doctrine QueryBuilder HAVING expression
body: <p>OK, so I'm rewriting some code, using Doctrine ORM (2.5).</p>
  
  <p>The old code creates a query that has something like this:</p>
  
  <pre><code>SELECT * FROM couples INNER JOIN individuals ON (couples.id = individuals.couple_id)
  GROUP BY couples.id
  HAVING SUM(individuals.date_of_birth &lt;= '1976-01-01') &gt; 0
  </code></pre>
  
  <p>I have no clue how to implement this best using the Doctrine QueryBuilder.  This is a very simplified example, the real query is much longer and has a few HAVING clauses, all of which use <code>SUM(some_condition) &gt; 0</code> to ensure that only Couples that contain a matching Individual will be retrieved.</p>
  
  <p>I can add having clauses in Doctrine using <code>$queryBuilder-&gt;having()</code>, but I cannot do so using the <code>SUM()</code> function.  Any ideas?</p>