SELECT
ROW_NUMBER() OVER (ORDER BY sequence) NEWSEQENCE
, type1
, type2
FROM (
SELECT
T1.id
, T1.sequence
, T1.type TYPE1
, T2.type TYPE2
FROM yourtable T1
INNER JOIN yourtable T2 ON T1.id = T2.id AND T1.sequence + 1 = T2.sequence
) X
;
I returned the sequence so it returns:
Open in new window
Not 1,2,3,4. In Oracle replacing the outer sequence with rownum will return 1,2,3,4. Not sure what the SQL Server equivalent is.
Open in new window