求代码如果存在记录(比如num=66)就把@i增加1 declare @i set @i=0 表格如下: id num 01 22 02 11 03 33 04 66 .. .. [解决办法]select @i=(case when num=66 then @i+1 else @i end) from T