I need to renumber rows by group (Class, Color, Type
) sequences in column SeqNo
from:
Class | Color | Type | SeqNo
Animal | Brown | Terr | 1
Animal | Brown | Aqua | 3
Animal | White | Terr | 3
Plant | Green | Aqua | 2
Plant | Green | Aqua | 2
Plant | Green | Aqua | 2
Platn | Green | Terr | 9
to:
Class | Color | Type | SeqNo
Animal | Brown | Terr | 1
Animal | Brown | Aqua | 2
Animal | White | Terr | 1
Plant | Green | Aqua | 1
Plant | Green | Aqua | 1
Plant | Green | Aqua | 1
Plant | Green | Terr | 2
How to do that, please?
You need to use
DENSE_RANK()
function to number your sequence and the CTE for the intermediary result set.The output: