I have to calculate my products stock cost, so for every product after each buy, i have to recalculate the Weighted Average Cost.
I got a view thats
I have spent several hours on this moving average! Mainly because of the not reliable window function first/last/nth_value, according to Postgresql documentation on window functions:
This is likely to give unhelpful results for nth_value and particularly last_value.
The answer is incomplete. Things to do:
SQLFiddle