I have the following table:
ID Data
1 A
2 A
2 B
3 A
3 B
4 C
5 D
6 A
6 B
etc .. In other words, I have data groups on an identifier. You will notice that the data group (A, B) occurs several times. I need a query that can identify individual groups of data and their number, for example:
DataID Data
101 A
102 A
102 B
103 C
104 D
Thus, DataID 102 will resemble data (A, B), DataID 103 will resemble data (C), etc. To be able to rewrite my source table in this form:
ID DataID
1 101
2 102
3 102
4 103
5 104
6 102
How can i do this?
PS. Code for creating the first table:
CREATE TABLE
INSERT INTO
SELECT 1, 'A'
UNION ALL SELECT 2, 'A'
UNION ALL SELECT 2, 'B'
UNION ALL SELECT 3, 'A'
UNION ALL SELECT 3, 'B'
UNION ALL SELECT 4, 'C'
UNION ALL SELECT 5, 'D'
UNION ALL SELECT 6, 'A'
UNION ALL SELECT 6, 'B'
source
share