i have a table of values that looks like the following:
voltage
9.7329000
7.6746300
8.5768950
7.9966500
3.5873950
5.6055000
7.5666250
0.6287800
i am looking for an SQL query to generate a histogram of values for a bucket size that may vary. for example, if the bucket size is 1.0, then the buckets the various counts fall into are [0.0,1.0), [1.0,2.0), [2.0,3.0), [3.0,4.0), ... in this case the query result for the data shown would be:
bucket count
0.0 1
3.0 1
5.0 1
7.0 3
8.0 1
9.0 1
[EDIT] so far i have the following:
select floor([voltage]/1)*1 as bucket_flr, count(*) as count
from [db1].[dbo].[table]
group by floor([voltage]/1)*1
order by floor([voltage]/1)*1
which seems to be working, but i was wondering if there is something a little more elegant. Thanks!