title: Misuse of aggregate in SQLite
body: <p>This error occurs in this <code>SQLite</code> query:</p>
  
  <pre><code>select f.rid, c.title, sum(some_expression) as ratio
  from doesntmatter
  where c.active = 1 or (ratio = 1.0 and c.active = 0
        and c.deactivated in (1, 2, 3, 4, 5)
  group by f.rid
  </code></pre>
  
  <p><a href="https://stackoverflow.com/questions/648083/sql-error-misuse-of-aggregate">This</a> question solves it with <code>having</code> clause:</p>
  
  <pre><code>select f.rid, c.title, sum(some_expression) as ratio
  from doesntmatter
  where c.active = 1 or (c.active = 0
        and c.deactivated in (1, 2, 3, 4, 5)
  group by f.rid
  having ratio = 1.0
  </code></pre>
  
  <p>But in my case this changes the semantics of the expression. Do you know how to achieve the expression that is in the original <code>where</code> clause?</p>