考虑下表
create table #table
(
Name varchar(100),
Group1 bigint,
Group2 bigint,
Group3 bigint
)
insert into #table values('Adam', 276328, 00001, 0)
insert into #table values('Bob', 276328, 00002, 0)
insert into #table values('Catherine', 927356, 00002, 0)
insert into #table values('Dave', 927356, 00003, 0)
insert into #table values('Eleanor', 927379, 00003, 0)
insert into #table values('Krampus', 927390, 00004, 0)
我正在尝试Group3使用新自动生成的组号更新列。
例如,最初这些名称被预先分组为“Adam, Bob”、“Catherine, Dave”、“Eleanor”,然后是“Krampus”,这从Group 1.
Group 2然后将名称分组为“Adam”、“Bob & Catherine”、“Dave & Eleanor”,然后是“Krampus”
我想要做的是,使用第 1 组和第 2 组来分配一个新的“第 3 组”,将它们全部分组。
类似于“Adam & Bob & Catherine & Dave & Eleanor”,因为 Adam 与 Bob 在第 1 组中分组,而 Bob 与 Catherine 在第 2 组中分组,这意味着它们都传递地分组在一起。
输出如下:
'Adam', 276328, 00001, 00001
'Bob', 276328, 00002, 00001
'Catherine', 927356, 00002, 00001
'Dave', 927356, 00003, 00001
'Eleanor', 927379, 00003, 00001
'Krampus', 927390, 00004, 00002
我玩过Rank(), Dense_Rank()- 但无法找到一种方法将它们全部传递分组。