I want to create a table to better illustrate my question
This is a sample of my data in oracle database
The work I want to do is step by step as follows
1-Group the values in the denominator columns by group_id column and calculate the least common multiple. For this action, I created lcm (least common multiple) and gcd (greatest common divisor) functions. added it here.
CREATE OR REPLACE function SAMPLE.lcm(a number, b number) return number is begin return (a*b)/gcd(a,b); end;
CREATE OR REPLACE function SAMPLE.gcd(a number, b number)
return number is
begin if b = 0 then return a; else return gcd(b,mod(a,b)); end if; end;
2-To increase the numerator values proportionally to values of the denominator column. mathematical formula like this :
(lcm(values of denominator(1..to -n)) / values of denominator ) * values of the numerator
3-summing the new calculated values by grouping them by group_id value
All of the items like sql, function, view that will make this work complete are suitable for me.
What can I do for this.
[TL;DR] Write your own custom aggregation function.
Given your
GCD
andLCM
functions:Then you can create a specification for a type to use in a custom aggregation:
With the body:
You can then create the custom aggregation function:
Then if you have the sample data:
You can use the query:
Which outputs:
db<>fiddle here