Skip to content
Advertisement

how to divide each row by the sum of those rows?

I have a table CREDITS with these columns:

  • DAY_OPERATIONAL
  • TOTAL_LOAN
  • CREDITS_PERCENT

I should multiply each row’s TOTAL_LOAN and CREDITS_PERCENT then divide to SUM(TOTAL_LOAN) in that DAY_OPERATIONAL.

My code is not working.

How can I achieve this? How do I need to use group by properly?

Advertisement

Answer

This is how I understood the question.

tc and tl are here just to show what values were used to compute the final result.

So:


As of day_operational: if its datatype is date (should be!), then don’t compare it to strings. '29.12.2021' is a string. Use

  • date literal (as I did): date '2021-12-29' or

  • to_date function with appropriate format mask:

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