Skip to content
Advertisement

Tag a row based on aggregate value condition

Here is my dataset, where order is the fix sequence of each product.

Initial data set

What I want is another column in here, lets say TagID. TagID is an int value that will based on the aggregate Count column, group it by product if it is greater or equal to 5.

So the dataset would look like this:

Desired results

How can I accomplish this in SQL Server?

Thanks in advance.

Advertisement

Answer

This requires a recursive CTE. You already have a numbering column, so this is pretty simple:

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