I am using SQL Server 2012 and need to generate a histogram, conceptually similar to Google's screener
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.
So, this is what I have so far:
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
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?
Thank you