当前位置: 代码迷 >> Sql Server >> 怎么使某一个字段在另一个字段相同值上自动增长
  详细解决方案

怎么使某一个字段在另一个字段相同值上自动增长

热度:80   发布时间:2016-04-27 11:23:18.0
如何使某一个字段在另一个字段相同值下自动增长
举例:有两个字段,在相同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
--2000select 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),categoryfrom  #t t  drop table #t
  相关解决方案