Reputation: 506
Spend half an hour trying to format my question but failed terribly (WHY IS IT SO DAMN HARD!?), so instead I'm going to post a picture that explains everything quite simply.
Some explanation, I have a table that has a set of columns that repeat in a predictable pattern, I want to query that pattern (please look at the picture to understand).
I'm still an amateur with SQL Server (started less than a month ago) and don't know where to begin.
Upvotes: 2
Views: 104
Reputation: 175576
Use DENSE_RANK
:
SELECT
row_number,
[GROUP_NUMBER] = DENSE_RANK() OVER (ORDER BY column1, column2, column3),
column1,
column2,
column3,
random_value
FROM tab
ORDER BY Row_Number;
Upvotes: 3