title: Generate histogram in SQL Server
body: <p>I am using SQL Server 2012 and need to generate a histogram, conceptually similar to <a href="https://www.google.com/finance#stockscreener" rel="nofollow">Google's screener</a></p>
  
  <p>The idea is to split all the prices into 100 equally sized (based on price) buckets, and then each bucket contains a number of items priced within the bucket's min and max. NTILE didn't work -- it tried to split items equally (based on count) among buckets. </p>
  
  <p>So, this is what I have so far:</p>
  
  <pre><code>select bucket, count(*) from (select cast((PERCENT_RANK() OVER(ORDER BY Price DESC)) *   100 as int) as bucket  from MyTable
  where DataDate = '4/26/2012') t group by bucket
  </code></pre>
  
  <p>Is this a good way to produce a histogram in SQL Server 2012? Is there anything built-in SQL Server 2012 to do this task or a better way?</p>
  
  <p>Thank you</p>