I want the result as per my image from a table in SQL Server 2008.
I assume, the best way to do is group based on Column B and Column C using NTILES to split the rows into TILE groups.
In that how can I set same values for the Column D within a group
- Group A -same column value in Column D
- Group B -same column value in
Column D (but it is different than Group A column D value)
So how can I access each group to set these values without a cursor?
PS:Rvalue1,Rvalue2,Rvalue3 ,RvalueX has no relation to each other,it is just random unique identifier(GUID for each group)
[edited as per comments from @Martin Smith]
The approach I followed:
Store the distinct ColB ColC values in a tableVariable having an Identity Column
Iterate through the tableVariable using a while loop and update the parent table ColD value based on the Values of ColB and ColC
Where
ColB and ColC values will be the value in each row of the condensed/grouped tableVariable.
The Identity column is used to iterate through the tableVariable row by row.