转:http://blog.sina.com.cn/s/blog_1512521570102wrfl.html
select cost,@a:=@a+1 from testone,(select @a:=0) as a;

mysql中变量不用事前申明,在用的时候直接用“@变量名”使用就可以了。
第一种用法:set @num=1; 或set @num:=1; //这里要使用变量来保存数据,直接使用@num变量
第二种用法:select @num:=1; 或 select @num:=字段名 from 表名 where ……
注意上面两种赋值符号,使用set时可以用“=”或“:=”,但是使用select时必须用“:=赋值”

相关文章:

  • 2021-10-27
  • 2021-08-03
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2020-10-08
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2021-12-08
相关资源
相似解决方案