Skip to content
Advertisement

MySQL lag() with default value previous row value

Here is my sqlfiddle – http://sqlfiddle.com/#!9/fa7b9a/2 .

How I can get with LAG() previous and current it this for March results?

Also how I can set first value to have for previous_val last FEB result and then to go as per usual?

Advertisement

Answer

One of possible solutions – calculate LAG for whole table and after that filter results:

SQL fiddle

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