读书人

怎么使某一个字段在另一个字段相同值上

发布时间: 2012-09-06 10:37:01 作者: rapoo

如何使某一个字段在另一个字段相同值下自动增长
举例:有两个字段,在相同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 

读书人网 >SQL Server

热点推荐