On Fri, Jul 28, 2017 at 12:21 PM, Steve Midgley <science@misuse.org> wrote:
The general logic is that anytime we find a record with a time_id null, we would like to update it with the previous time_id that is not null.
I use the LAG function and the below code
Lag can be made to work but only if you know that maximum lag that guarantees a non-null value is present. If you cannot pick a reasonable number then you should write a custom aggregate function. I believe I've seen posts (probably to -general) detailing this and you might find it in blog posts or the like as well. I'm unable to provide a working example right now.