Skip to content
Advertisement

Ranking in SQL Server with a column change

Below is the original table that I want to rank according to the column changes by Install_Status and Dates for each product.

enter image description here

Query:

This SQL query returns the following results:

enter image description here

However, I am not getting appropriate ranking for product A by date. My expected result is as below:

enter image description here

Advertisement

Answer

You seem to want to count the changes. For this use lag() and a cumulative sum:

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