如何使某一个字段在另一个字段相同值下自动增长
举例:有两个字段,在相同category下,ID实现自动增长
ID   category
1       a
2       a
3       a
1       b
2       b
1       c
如何实现以上的效果?求高手指教!
------解决方案--------------------select id=row_number() over(partition by category order by getdate()),
      category
from tb
------解决方案--------------------SQL code
--2000
select id0=identity(int,1,1),*into #t from tb 
select
  id=(select count(1)+1  from #t where id0<t.id0 and category=t.category),category
from
  #t t
  
drop table #t