Use of Analytical Function in Query, select against budget, CSUM

Database

Use of Analytical Function in Query, select against budget, CSUM

Dears,
Need a support in handling a case. Below, I have set of projects with profitability & investment required. My total budget is 100. I have to select projects sorted in order of profitability within my budget.  I have explained scenarios & attached a pic for reference.
 
Current:   I am sorting on profitability & taking cumulative investment sum for each record. And comparing this cumulative value against the Budget and select the projects. In such case, only A&B projects are selected.
Problem:  As per my current selection, I am only selecting A&B projects. After that, I still have 10 left in my budget, but not able to select projects.
Requirement:  As I still have money 10, I can still select project D,F. But due to cumulative logic, one project with big investment is automatically making next projects rejected even if I have left in my budget.
 

 
BR
Abhijit
  • analytical
  • csum
  • functions
  • preceding
  • unbounded
Tags (1)