Почему не функция DENSE_RANK ?
with
t as(
select * from (values
('Set A', '01/31/1980', 'Base', 64.007, 'Monthly', 49, 1, 2),
('Set A', '02/29/1980', 'Base', 64.014, 'Monthly', 49, 1, 2),
('Set A', '03/31/1980', 'Stress', 64.015, 'Monthly', 49, 2, 2),
('Set A', '04/30/1980', 'Stress', 64.008, 'Monthly', 49, 2, 2),
('Set B', '05/31/1980', 'Storm', 63.993, 'Monthly', 54, 5, 2),
('Set B', '06/30/1980', 'Raptor', 63.972, 'Monthly', 54, 24, 2),
('Set B', '07/31/1980', 'Agile', 63.788, 'Monthly', 54, 25, 2),
('Set B', '08/31/1980', 'Pond', 63.868, 'Monthly', 54, 27, 2),
('Set B', '07/31/1980', 'Agile', 63.212, 'Monthly', 54, 25, 2),
('Set B', '07/31/1980', 'Pond', 63.457, 'Monthly', 54, 6, 2)
)v(DataSetName, "Date", Sname, Level, Frequency, SetId, ScenarioId, FrequencyId)
)
select *,
dense_rank() over(order by DataSetName, Sname) S_row_id
from t;
DataSetName Date Sname Level Frequency SetId ScenarioId FrequencyId S_row_id
Set A 02/29/1980 Base 64,014 Monthly 49 1 2 1
Set A 01/31/1980 Base 64,007 Monthly 49 1 2 1
Set A 04/30/1980 Stress 64,008 Monthly 49 2 2 2
Set A 03/31/1980 Stress 64,015 Monthly 49 2 2 2
Set B 07/31/1980 Agile 63,788 Monthly 54 25 2 3
Set B 07/31/1980 Agile 63,212 Monthly 54 25 2 3
Set B 07/31/1980 Pond 63,457 Monthly 54 6 2 4
Set B 08/31/1980 Pond 63,868 Monthly 54 27 2 4
Set B 06/30/1980 Raptor 63,972 Monthly 54 24 2 5
Set B 05/31/1980 Storm 63,993 Monthly 54 5 2 6