2、此时我们想再多加一列为序号列,让序号递增

修改sql如下
select (@xh := @xh + 1) as xh, a.* from (select * from auto where level = 3) a, (select @xh := 0) x;

3、语句解析
:= 在mysql中是赋值操作, @xh 在mysql是变量, (@xh := @xh + 1) as xh 意思相当于java中的 a = a + 1 , 后面的 (select @xh := 0) x 相当java中的 a = 0 ,最后执行整条sql,mysql先执行from后的语句,此时 (select * from auto where level = 3) a 会产生一张虚表, (select @xh := 0) x; 会将 @xh 变量赋值为0,最后执行from前面的语句,就出现上述结果
附上mysql查询语句时,关键字顺序和执行查询时顺序
关键字顺序
select
where  
group by  
having  
union  
order by  
limit
查询时执行顺序
where group by having select distinct