Database Reference
In-Depth Information
Figure 8-3. Transformation of a frequency histogram into a height-balanced histogram
The following query is an example of how to produce such a height-balanced histogram for the val2 column.
Figure 8-4 shows a graphical representation of the data it returns. Notice how the endpoint value of each bucket is the
value at the point where the split occurs. In addition, a bucket 0 is added to store the minimum value:
SQL> SELECT count(*), max(val2) AS endpoint_value, endpoint_number
2 FROM (
3 SELECT val2, ntile(5) OVER (ORDER BY val2) AS endpoint_number
4 FROM t
5 )
6 GROUP BY endpoint_number
7 ORDER BY endpoint_number;
COUNT(*) ENDPOINT_VALUE ENDPOINT_NUMBER
---------- -------------- ---------------
200 104 1
200 105 2
200 105 3
200 106 4
200 106 5
Search WWH ::




Custom Search