DECLARE @T table (CustomerID int, Attempt int, score decimal(10,2) )
INSERT INTO @T
VALUES
(111, 1, 1)
,(111, 2, 1)
,(111, 3, 1)
,(111, 4, 0.5)
,(111, 5, 1)
,(111, 6, 0)
,(222, 5, 0.5)
,(222, 6, 1)
,(222, 7, 0.5)
,(222, 8, 1)
,(222, 9, 1)
,(222, 110, 1)
select t.*,
(case when t.score < 1 then 0
else row_number() over (partition by t.customerId, grp order by t.attempt)
end) as ranking
from (select t.*,
sum(case when score < 1.00 then 1 else 0 end) over (partition by t.customerId order by t.attempt) as grp
from @t t
) t;