SQL Server 2008:
Sorry for the possibly non-informative title but I’m not sure quite how to descirbe this problem. I am sure there is a really neat (and probably obvious!) way of solving it but I just can’t think.
Anyway, given input…
ObjectID Field1 Field2 Field3 (actually about 10-12 fields some varchar(max)
1 x y z
2 x y z
3 x y b
4 x q r
I want to attach to each row a key that indicates to which ‘grouping’ it belongs. i.e. kind of like if you did a “GROUP BY Field1, Field2, Field3”. Need to end up with information equivalent to this…. not saying it has to look like this, but the “GroupID” has to be a GUID not an integer.
GroupID ObjectID
[guid1] 1
[guid1] 2
[guid2] 3
[guid3] 4
(Probably) needs to be a set operation (input may be many 1000s of rows), needs to be as fast as possible as it also will happen fairly often. I thought about hashing the column values – but there is at least one varchar(max) field… in any case I don’t know if/how to actually do that in SQL either! [Not allergic to cursors but worry about speed – and don’t have good tools to run comparative tests].
As I said, the soultion is probably really obvious once you know it, but I really can’t think, been bashing my brain for a good few hours over a coupla days now.
I think DENSE_RANK() is what you need here: