我对SQL一点也不懂,
请大家帮偶写一个东东,然后再告诉我怎么用哈
描述:
prodserial是一个自动编号列(5位递增,根据sortid的不同递增)
比如,
sortid 为129
prodserial
00001
00002
....
sortid 为187
prodserial
00001
00002
....
请大家帮偶写一个东东,然后再告诉我怎么用哈
描述:
prodserial是一个自动编号列(5位递增,根据sortid的不同递增)
比如,
sortid 为129
prodserial
00001
00002
....
sortid 为187
prodserial
00001
00002
....
insert test default values
insert test default values
insert test default valuesselect * from testdrop table test
那为什么
sortid 为129
prodserial
00001
00002
....
sortid 为187
prodserial
00001
00002
....
129和187不同才对呀
id int identity
sortid int ,
... --其它字段
)
go
select sortid,(select count(*) from test where sortid=a.sortid and id<=a.id) as prodserial
from test a
order by 1,2
... 其它字段
from test a
order by 1,2