Search code examples
sqloracleanalytical

How to find regions where total of their sale exceeded 60%


I have a table interest_summary table with two columns:

  • int_rate number,
  • total_balance number

example

10.25  50
10.50 100
10.75 240
11.00  20

My query should return in 2 columns or a string like 10.50 to 10.75 because adding their total exceed 60% of total amount added together

Could you suggest a logic in Oracle?


Solution

  • select 
      min(int_rate), 
      max(int_rate) 
    from 
      (
        select 
          int_rate,   
          nvl(sum(total_balance) over(
            order by total_balance desc
            rows between unbounded preceding and 1 preceding
          ),0) as part_sum
        from interest_summary
      )
    where 
      part_sum < (select 0.6*sum(total_balance) from interest_summary)
    

    fiddle