Say I have a table with a range column (float) where the values are from 1 to 10. I want to see the distribution of rows according to range. I can do something like this:
SELECT floor(range) AS range_bin, COUNT(*) FROM tbl_name GROUP BY range_bin ORDER BY range_bin;
and get an output like this:
range_bin count(*)
0 5
1 22
4 17
5 12
6 10
7 7
9 3
Note that there are no rows for range_bin = 2,3,8 because the data didn't have any values in that range.
Is there a way to get the query to include those rows with a 0 in the count(*) column??
For non-trivial, multidimensional histograms this is a PITA when you go to plot the data.
If it matters, this is on MySQL v4.1
SELECT floor(range) AS range_bin, COUNT(*) FROM tbl_name GROUP BY range_bin ORDER BY range_bin;
and get an output like this:
range_bin count(*)
0 5
1 22
4 17
5 12
6 10
7 7
9 3
Note that there are no rows for range_bin = 2,3,8 because the data didn't have any values in that range.
Is there a way to get the query to include those rows with a 0 in the count(*) column??
For non-trivial, multidimensional histograms this is a PITA when you go to plot the data.
If it matters, this is on MySQL v4.1