单条语句不能胜任,需要写个批或存储过程来实现,但编程语法在各大数据库中有所不同,你的数据库是哪种或哪家的?
假设:
1、表名是ATable
2、序号字段名是XH
3、编码字段名是BM,类型是int
如实际情况与上有异,请自行替换
declare @XH int,
@BM int
set @XH = 10
declare EnumRow Cursor
for select BM from ATable order by BM
for read only
open EnumRow
fetch EnumRow into @BM
while @@sqlstatus = 0
begin
update ATable set XH = @XH where BM = @BM
set @XH = @XH + 10
fetch EnumRow into @BM
end
close EnumRow
deallocate cursor EnumRow
还有一种方法,或许性能更好
create table ATable_2 ( XH int identity, BM int )
insert ATable_2( BM ) select BM from ATable order by BM
update ATable
set XH = b.XH * 10
from ATable a, ATable_2 b
where a.BM = b.BM
drop table ATable_2
SELECT * FROM `id` ORDER BY posts DESC limit 10, ; 然后update一下就行了