老办法,相关子查询~
效率不高,想提高效率,用SQL 2005
declare @t table(item varchar(10),groupname varchar)
insert @t select 'a1','a'
union all select 'a2','a'
union all select 'a3','a'
union all select 'b1','b'
union all select 'b2','b'
union all select 'c1','c'
union all select 'd1','d'
union all select 'd2','d'
select * from @t
select *,
ranks=1+(select count(1) from @t B where A.groupname=groupname and item<A.item)
from @t A