Skip to content
Advertisement

Oracle – How to partition by case statement

I have the following Oracle SQL in a report that I inherited. The bucket1_days_prc and overdue_prc should show the percentage of the number of invoices that falls within those buckets based on the number of days overdue. I haven’t worked with windowing functions in ages, so I can’t figure out how to incorporate the case date range into the windowing function. Currently the value just divides by itself (although it apparently worked before) and always gives 100%. How can I identify the number of invoices that fall in the bucket for that case date range and divide it by the total number of invoices? The columns must basically repeat the answer or show null in order to work with BI Publisher (I hope).

The percentage of data in each bucket is needed, so if there is two invoices out of four total in the 0-9 days bucket then that would be 50%.

Sample data and expected output

enter image description here

Advertisement

Answer

Managed to fix it with:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement