user7256821
user7256821

Reputation: 69

Introduce incremental run number in sql based on another column

I am trying to replicate below table, last column "Run number" is the desired output. Based on run flag column, this run number increments (at 1) or maintains (at 0) its value as shown.

Based on similar questions on this site and google, I tested Row_number function but I can't find right column to decide partitions. enter image description here

Upvotes: 0

Views: 121

Answers (1)

John Cappelletti
John Cappelletti

Reputation: 81990

You can use the window function sum() over()

...
RunNumber = sum([Run Start Flag]) over ( order by [Product Created Date])
...

Upvotes: 1

Related Questions