title: Grouping data into buckets - SQL
body: <p>I'm trying to get SQL to group some continuous data into two buckets, but it raises me an "aggregate functions are not allowed in the GROUP BY clause" error. How can I circumvent that ?</p>
  
  <pre><code>SELECT
  (CASE WHEN AVG(amount) BETWEEN 0 AND 100000 THEN "Group 1"
  WHEN AVG(amount) &gt; 100000 THEN "Group 2" END) AS Bucket
  , AVG(amount)
  FROM DB
  GROUP BY bucket
  </code></pre>