I have a table with the following columns:
id integer
sumqty numeric
maxqty numeric
The columns id, sumqty are updated by other functions regularly.
I need to write a function that pass on these two columns and update the maxqty column.
for example:
id, sumqty, maxqty
5 20
5 70
5 45
3 20
1 12
1 2.5
after function runs, desired output will be:
id, sumqty, maxqty
5 20 45
5 10 45
5 45 45
3 20 20
1 12 12
1 2.5 12
I wrote this code:
update A set maxqty= (select MAX(sumqty) OVER (PARTITION BY id))
but it doesn't always works. Sometimes it doesn't give me the actualy MAX.
What is the problem with my code?