title: SQLAlchemy func.count on boolean column
body: <p>How can I count easily the number of rows where a particular column is <code>true</code> and the number where it is <code>false</code> ? </p>
  
  <p>I can't (or can I ?) run the query with count() because I'm embedding this count in a having() clause, like :</p>
  
  <pre><code>.having(func.count(Question.accepted) &gt;
          func.count(not_(Question.accepted)))
  </code></pre>
  
  <p>but with the above way, the function counts every line on both sides of the inequality.</p>
  
  <p>I tried something like this</p>
  
  <pre><code>.having(func.count(func.if_(Question.accepted, 1, 0)) &gt;
          func.count(func.if_(Question.accepted, 0, 1)))
  </code></pre>
  
  <p>But I get an error</p>
  
  <blockquote>
    <p>function if(boolean, integer, integer) does not exist</p>
  </blockquote>
  
  <p>(seems it doesn't exist in postgresql).</p>
  
  <p>How can I count easily the number of rows where column is true and false ?</p>