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:

  1. period start data 01/01/2015
  2. period end date 01/01/2016
  3. 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

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -