Skip to content
Advertisement

Build change history from table with historical row values

I have table that is storing historical values for data in other table:

Now I need to generate from such table “change log” which will show what was old value, new value and when update occur:

Unfortunately, I can’t change structure of the existing table and can’t put old value there, I need a query to extract this.

Advertisement

Answer

You can use window function lead() to do partition on ObjectId. Here is the demo.

output:

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement