title: Can't fix this: "Cannot group by an aggregate"
body: <p>Sorry for the silly question. I have read a lot of threads about the same issue, but still, can't fix this...</p>
  
  <pre><code>SELECT   company_name, SUM(clicks)
  FROM     table1
  WHERE    code = 'ES'
  GROUP BY 1
  ORDER BY clicks DESC
  LIMIT 100;
  </code></pre>
  
  <p>This results in:</p>
  
  <blockquote>
    <p>Expression 'clicks' is not present in the GROUP BY list  </p>
  </blockquote>
  
  <p>And if I try this:</p>
  
  <pre><code>SELECT   company_name, SUM(clicks)
  FROM     table1
  WHERE    code = 'ES'
  GROUP BY 1,2
  ORDER BY clicks DESC
  LIMIT 100;
  </code></pre>
  
  <p>This is what I get:</p>
  
  <blockquote>
    <p>Cannot group by an aggregate.  </p>
  </blockquote>
  
  <p>If I try with no aggregation on "clicks":</p>
  
  <pre><code>SELECT   company_name, clicks
  FROM     table1
  WHERE    code = 'ES'
  GROUP BY 1
  ORDER BY clicks DESC
  LIMIT 100;
  </code></pre>
  
  <blockquote>
    <p>Error: Expression 'clicks' is not present in the GROUP BY list</p>
  </blockquote>
  
  <p>And if add clicks to the group by:</p>
  
  <pre><code>SELECT   company_name, clicks
  FROM     table1
  WHERE    code = 'ES'
  GROUP BY 1,2
  ORDER BY clicks DESC
  LIMIT 100;
  </code></pre>
  
  <p>The results are not what I need:</p>
  
  <pre><code>Company_name | clicks
  -------------+--------
      company1 | 250   
      company1 | 340
      company2 | 100 
      company2 | 300
      company2 | 344
  </code></pre>
  
  <p>How can I get?:</p>
  
  <pre><code>Company_name | clicks
  -------------+-------
      company1 | 590
      company2 | 744
  </code></pre>
  
  <p>Thank you!</p>