title: SQL for bucketing counts
body: <p>I'm trying to create a histogram of people's reputations who ask questions on the site using StackExchange data explorer.</p>
  
  <p>The following gives error message:</p>
  
  <pre><code>Each GROUP BY expression must contain at least one column that 
  is not an outer reference.
  Invalid column name 'lt_100'. ...
  </code></pre>
  
  <p>Suggestions appreciated</p>
  
  <pre><code>select
    case when Reputation &lt; 100    then "lt_100"
         when Reputation &gt;= 100 and Reputation &lt; 200   then "100_199"
         when Reputation &gt;= 200 and Reputation &lt; 300   then "200_299"
         when Reputation &gt;= 300 and Reputation &lt; 400   then "300_399"
         when Reputation &gt;= 400 and Reputation &lt; 500   then "400_499"
         when Reputation &gt;= 500 and Reputation &lt; 600   then "500_599"
         when Reputation &gt;= 600 and Reputation &lt; 700   then "600_699"
         when Reputation &gt;= 700 and Reputation &lt; 800   then "700_799"
         when Reputation &gt;= 800 and Reputation &lt; 900   then "800_899"
         when Reputation &gt;= 900 and Reputation &lt; 1000  then "900_999"
         else "over 1000"
    end  ReputationRange,
    count(*) as TotalWithinRange
  FROM Users
  JOIN Posts ON Users.Id = Posts.OwnerUserId 
  JOIN PostTags ON PostTags.PostId = Posts.Id
  JOIN Tags on Tags.Id = PostTags.TagId
  WHERE PostTypeId = 1 and Posts.CreationDate &gt; '9/1/2010'
  Group by 
  1
  </code></pre>