/*需求是这样,有一张表T,里面有字段A,B,C/*需求是这样,有一张表T,里面有字段A,B,C A为自增型的PK,B为普通字段,C为int型的字段 现在要求把表T里的记录按字段C顺序排,同时把C的值按1,2,3,4..这样依次重新赋值. 比如: 表T -------------------- A B C -------------------- 1 w 6 2 d 4 3 # 9 4 t 3 按上述要求,排序赋值后数据会变成如下形式 -------------------- A B C -------------------- 1 w 3 2 d 2 3 # 4 4 t 1 请SQL语句强人指点.*/ if not object_id('T') is null drop table T Go Create table T([A] int,[B] nvarchar(1),[C] int) Insert T select 1,N'w',6 union all select 2,N'd',4 union all select 3,N'#',9 union all select 4,N't',3 Go update t set c=cnt from( select *,CNT=(select count(*) from T where [C]<=s.[C]) from t s)a where a.[A] =t.[A] select * from T select *,CNT=(select count(*) from T where [C]<=s.[C]) from t s