Hi
This seems to me such a common thing to want to do
I've got a table with a numeric column. In this case, it is a purity value, which ranges from 0 to 100%, to two decimal places. There are a few hundred thousand rows.
What I'd like to do is produce a histogram showing the frequency distribution for each "bin" range that I define.
The first step is to get the SQL
So I'd like the following result set
0-20% - 100,000
20-40% - 200,000
40-60% - 400,000
etc.
The only way I can think to do this is
Select Count(ID) from Table Group By MyBinFunction(Purity);
where MyBinFunction would be a PL/SQL function which returns the correct bin for any numeric value. For example, for 15.56% it would return "0-20%"
This seems inelegant to me, and my question is "Is there an easier way"
All my searching on the net points my to analyzing tables for the CBO, which is not what I want, but indicates that Oracle already does something like this internally?
Thanks
Mark
Mark![[openup] [openup] [openup]](/data/assets/smilies/openup.gif)
This seems to me such a common thing to want to do
I've got a table with a numeric column. In this case, it is a purity value, which ranges from 0 to 100%, to two decimal places. There are a few hundred thousand rows.
What I'd like to do is produce a histogram showing the frequency distribution for each "bin" range that I define.
The first step is to get the SQL
So I'd like the following result set
0-20% - 100,000
20-40% - 200,000
40-60% - 400,000
etc.
The only way I can think to do this is
Select Count(ID) from Table Group By MyBinFunction(Purity);
where MyBinFunction would be a PL/SQL function which returns the correct bin for any numeric value. For example, for 15.56% it would return "0-20%"
This seems inelegant to me, and my question is "Is there an easier way"
All my searching on the net points my to analyzing tables for the CBO, which is not what I want, but indicates that Oracle already does something like this internally?
Thanks
Mark
Mark
![[openup] [openup] [openup]](/data/assets/smilies/openup.gif)