sql - Select statement that divides arbitrary data into buckets that sum up to a specific value -
is there way in oracle database of dividing amount of money several buckets equal parts , making sure sum of money equal initial 1 single select
statement?
maybe fancy combination of aggregate functions?
for example: have amount of 100 dollars , 3 time buckets. need query result in like
(33.33, 33.33, 33.34)
so last value equilibrates there.
example data:
- period start data 01/01/2015
- period end date 01/01/2016
- total volume 121 tons
i need sql command output equally distributed total volume among months @ end:
jan - 10 feb - 10 ... nov - 10 dec - 11
if have table of time buckets, use window functions:
select 100.0 / count(*) on () bucket_amount buckets b;
note gives equal amount three, there no 33.34. can tweaked purpose, need provide sample data , desired results.
Comments
Post a Comment