CREATE TABLE widgets (widget_type VARCHAR2(10)) / DECLARE z NUMBER := 1; BEGIN FOR y IN 1..10 LOOP FOR x IN 1..10 LOOP INSERT INTO widgets VALUES ('Type ' || z); z := z + 1; END LOOP; z := 1; END LOOP; END; /If you wanted to sum them based on type and just see the first five types, you can use a simple SQL statement like this:
SELECT NULL link, widget_type label, COUNT(*) value FROM widgets GROUP BY widget_type ORDER BY 2Which will in turn, produce a chart that looks like this: Clearly, not what you may expected, as you only wanted to see the top 5 widgets, not the top 5 plus all additional records grouped into an "other" slice. Visually, this may be misleading to the user. To get just the top 5 records, we have to use an inline SQL statement that will select from our original SQL statement and limit the results to just 5 records:
SELECT link, label, value FROM ( SELECT NULL link, widget_type label, COUNT(*) value FROM widgets GROUP BY widget_type ORDER BY 2 ) WHERE rownum < 6With this approach, we let APEX create the chart and append the Other slice to the results. We then siphon off just the first five records, which in this case, will not include the Other slice. The result is something closer to what many users would expect: Using this approach, the value of the Maximum Rows can be set anything greater than or equal to the value compared to ROWNUM in the last line of the second SQL statement, as we will be using the WHERE clause to limit how many records are displayed.