带变量的mysql子查询

lhcgjxsq  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(404)

如何将mysql变量传递给子查询,如下所示。

select
 v.val, @var:= @var + 1 var 
from 
 (select val from table where id=@var) v, 
 (select @var:= 0) var
ruarlubt

ruarlubt1#

select
 v.val ,var
from 
(select val, @var:= @var + 1 var from Table1,(select @var:= 0) var where id=@var+1) v

演示
http://sqlfiddle.com/#!2014年9月765e9c

相关问题