Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-02-10 : 09:51:16
|
hiI have this data:A 1A 2A 3A 4A 5B 1B 2B 3B 4B 5C 1C 2C 3C 4C 5I would like to have a group id number based on every 3 rows. The result should look like this1 A 11 A 21 A 32 A 42 A 51 B 11 B 21 B 32 B 42 B 51 C 11 C 21 C 32 C 42 C 5How should I go about it? Thanks a lot |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-11 : 00:59:56
|
[code]SELECT ((ROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY Col2)-1)/3)+1 AS Seq,Col1,Col2FROM Table[/code]------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2014-02-11 : 08:29:56
|
thanks visakh16 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2014-02-12 : 00:02:29
|
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
|
|
|
|
|