declare @tb table(F1 int,F2 varchar(10))
insert @tb
select 1,'A' union
select 2,'B' union
select 3,'B' union
select 4,'C' union
select 5,'C' union
select 6,'C'
select [F1]=(select count(1) from (select distinct F2 from @tb)A where F2<=t.F2),
F2
from @tb t
where not exists(select 1 from @tb where F2=t.F2 and F1>t.F1)
declare @tb table(F1 int,F2 varchar(10))
insert @tb
select 1,'A' union
select 2,'B' union
select 3,'B' union
select 4,'C' union
select 5,'C' union
select 6,'C'
select [F1]=(select count(1) from (select distinct F2 from @tb)A where F2<=t.F2),
F2
from @tb t
where not exists(select 1 from @tb where F2=t.F2 and F1>t.F1)