title: SQL error: misuse of aggregate
body: <p>SQLite version 3.4.0
  What's wrong with aggregate functions? Additionally, I suspect that ORDER BY won't work as well. How to rewrite this? </p>
  
  <pre><code>sqlite&gt; SELECT p1.domain_id, p2.domain_id, COUNT(p1.domain_id) AS d1, COUNT(p2.domain_id) AS d2
     ...&gt; FROM PDB as p1, Interacting_PDBs as i1, PDB as p2, Interacting_PDBs as i2
     ...&gt; WHERE p1.id = i1.PDB_first_id
     ...&gt; AND p2.id = i2.PDB_second_id
     ...&gt; AND i1.id = i2.id
     ...&gt; AND d1&gt;100
     ...&gt; AND d2&gt;100
     ...&gt; ORDER BY d1, d2;
  SQL error: misuse of aggregate: 
  sqlite&gt;
  </code></pre>