Quantcast
Channel: SQLServerCentral » SQL Server 2014 » Development - SQL Server 2014 » Latest topics
Viewing all articles
Browse latest Browse all 3145

Need unique number for groups of records

$
0
0
Hi,I'm trying to do the following and haven't been able to figure it out.Say there's a table with these records:Col1 Col2 Col3a b ca b ca b de f ge f gI want to generate a number that represents the groups of columns like this:Col1 Col2 Col3 MyNumbera b c 1a b c 1a b d 2e f g 3e f g 3So that each grouping gets its own identifier. I've tried this:SELECT Col1, Col2, Col3 row_number() OVER (PARTITION BY Col1, Col2, Col3 ORDER BY Col1, Col2, Col3) AS MyNumber FROM MyTableBut I get this:Col1 Col2 Col3 MyNumbera b c 1a b c 2a b d 1e f g 1e f g 2See my problem? Any input greatly appreciated!!!!Rebecca

Viewing all articles
Browse latest Browse all 3145

Trending Articles