Is there an SQL statement to perform greedy number partitioning? (Oracle 19c)
I want to divide jobs among N processors.
Example,
Given the following workload data set:
job
---
4
60
50
1
100
6
Expected result set (assuming just N=2 where ties go to the processor with the fewest number of jobs assigned to it):
job processor
--- ---------
100 1
60 2
50 2
6 1
4 1
1 2
The following table may help clarify how those processors were assigned.
job processor length count
--- --------- ------ -----
100 1 100 1
60 2 60 1
50 2 110 2
6 1 106 2
4 1 110 3
1 2 111 3
Some combination of analytic functions and hierarchical queries seems like it could make this happen without having to resort to procedural code. Thanks in advance for your thoughts and assistance.