Pleased to have had the opportunity to use my brain on a programming (#SQL) task.
It was a bit like working out compound interest, when the interest rate changes every year. The task was:
In a manufacturing process, there are various losses of material at each step. Each input component has a cost per kg, so when the mass of the final output is less, the cost per kg of items produced goes up (using costs from the original materials).
Now each processing step has a known loss (e.g. 5% for one step, 6% for the next). The loss acts on what's left from the step before, so is compound.
We want a report of the amount of money lost at each step of the way, with a final total at the end.
The solution involved creating a new #Postgresql operator to do a cumulative multiplication (Postgres can do cumulative sums but not multiplications out of the box) and Window functions, so made my day
Glad to have the help of colleagues as well.