Skip to content
Advertisement

How restart the incremenal from a temp table in SQL

I want to try to do an incremental number for a table, that has to return to 0 when seeing from the previous column (LAG) 0.

This is what I tried to do:

And this is what I am expecting to get out:

I’m not familiar with the WITH common_table_expression is the right way to solve my problem?

Advertisement

Answer

You can use apply to fill blank value to next c :

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