0

我需要为记录的子集分配等级。样本数据:

Colour Code        Size Code
DWMUL040             7
DWMUL040             8
DWMUL040             9
DWMUL040             10
DWMUL040             7
DWMUL040             8
DWMUL040             9
DWMUL040             10
DWMUL040             7
DWMUL040             8
DWMUL040             9
DWMUL040             10
DWMUL040             7
DWMUL040             8
DWMUL040             9
DWMUL040             10

我需要数据看起来像这样:

Group ID            Colour Code        Size Code
1                   DWMUL040             7
1                   DWMUL040             8
1                   DWMUL040             9
1                   DWMUL040             10
2                   DWMUL040             7
2                   DWMUL040             8
2                   DWMUL040             9
2                   DWMUL040             10
3                   DWMUL040             7
3                   DWMUL040             8
3                   DWMUL040             9
3                   DWMUL040             10
4                   DWMUL040             7
4                   DWMUL040             8
4                   DWMUL040             9
4                   DWMUL040             10

该列表将被排序,并且基本上,每当尺寸代码更改时,它就是一个新组。我有一种感觉,这会很难,因为尺码(这些是服装尺码)可以是任何“例如 XL”。

4

1 回答 1

0
  select [colour code], [size code],
         row_number() over (partition by [colour code], [size code]
                            order by 1/0) [group id]
    from tbl
order by [group id], [colour code], [size code];
于 2012-12-21T00:59:46.693 回答