title: How to have 'distinct' in having clause
body: <p>EDIT: This is an example relation! I need it to work on a bigger relation so no workarounds!</p>
  
  <p>So I was given a simple task and at first I didn't see what could possibly be wrong and now I just don't understand why it doesnt work.</p>
  
  <p>Lets say I have a table of people and their friends and I want to select the ones who have 2 or more friends.</p>
  
  <p><strong>people</strong></p>
  
  <pre><code>------------------------------
  |person  | friend | relation |
  |-----------------------------
  |ana     | jon    | friend   |
  |ana     | jon    | lover    |
  |ana     | phillip| friend   |
  |ana     | kiki   | friend   |
  |mary    | jannet | friend   |
  |mary    | jannet | lover    |
  |peter   | july   | friend   |
  </code></pre>
  
  <hr>
  
  <p>I would want to do a</p>
  
  <pre><code> SELECT person FROM people GROUP BY person HAVING count(distinct friend) &gt; 1;
  </code></pre>
  
  <p>and get</p>
  
  <pre><code>-------
  | ana |
  -------
  </code></pre>
  
  <p>But I get a syntax error when using the '<code>distinct</code>' in the HAVING clause.
  I understand that the '<code>distinct</code>' is a part of the projection clause but
  how do I make '<code>count</code>' only count distinct entries without an additional subquery or something?</p>
  
  <p>EDIT: The best I could come up with is:</p>
  
  <pre><code>SELECT tmp.person FROM (SELECT person, count(distinct friend) 
               AS numfriends FROM people GROUP BY person) AS tmp 
         WHERE tmp.numfriends &gt; 1;
  </code></pre>