I have a table and I want to write a query which will give duplicate rows of that table based on the value of column quantity in that table.
Suppose the table is one given below
name | quantity
------|----------
a | 1
b | 1
c | 3
d | 2
e | 1
And I want to be able to write a query in T-SQL so that it would give a result which would look like follows;
name | number | quantity
------|--------|----------
a | 1 | 1
b | 1 | 1
c | 1 | 3
c | 2 | 3
c | 3 | 3
d | 1 | 2
d | 2 | 2
e | 1 | 1
So in this result, there are 3 rows for "c" as its quantity is 3 and the number increments as the line appears for nth time.
I have found this question which has been answered and accepted, but I don't quite understand how to apply it in to my scenario. Any help on this is much appreciated..!