Oracle Sql Create Pdf From Data
So I am trying to create a Probability Density Function from data in an Oracle SQL table through a SQL query. So consider the below table: Name | Spend -------------- Anne | 11
Solution 1:
You can try using WIDTH_BUCKET function.
select bucket , count(name)
from (select name, spend,
WIDTH_BUCKET(spend, 0, 200, 4) bucket
from mytable
)
groupby bucket
orderby bucket;
Here I have divided the range 0 to 200 into 4 bucket. And the function assigns a bucket number to each value. You can group by this bucket and count how many reocrds fall in each bucket.
Demo here.
You can even display the actual bucket range.
select bucket,
cast(min_value + ((bucket-1) * (max_value-min_value)/buckets) as varchar2(10))
||'-'||cast(min_value + ((bucket) * (max_value-min_value)/buckets) as varchar2(10)),
count(name) c
from (select name,
spend,
WIDTH_BUCKET(spend, min_value, max_value, buckets) bucket
from mytable)
groupby bucket
orderby bucket;
Sample here.
Solution 2:
SELECTCOUNT(*) y_axis,
X_AXIS
FROM
(SELECTCOUNT(*)y_axis,
CASEWHEN spend <=50THEN50WHEN spend <100AND spend >50THEN100WHEN spend <150AND spend >=100THEN150WHEN spend <200AND spend >=150THEN200END x_axis
FROM your_table
GROUPBY spend
)
GROUPBY X_AXIS;
y_axis x_axis
-----------------410015012002150
Post a Comment for "Oracle Sql Create Pdf From Data"