declare @a table
(
id int,
type char(1)
)
insert into @a
select 1,'A' union all
select 2,'B' union all
select 3,'C' union all
select 4,'A' union all
select 5,'B' union all
select 6,'C' union all
select 7,'A' union all
select 8,'B' union all
select 9,'C'
select *
from @a a
order by (select count(1) from @a where id<a.id and type=a.type)desc,id