相同值序号一样,select中的变量是从左到右赋值生效的。
set @newrow:=0;
set @val = -0.01;
select id,(case when ifnull(@val,-1.1) <> ifnull(AAA_yfjfbz,-1.1) then @newrow:=@newrow+1 else @newrow end) as newid,(p_pcount - @newrow + 1) as star,(@val:=AAA_yfjfbz) as dbval from AAA_element where area_clstype = p_clstype order by AAA_yfjfbz desc;