mysql–使用变量为每行生成行号

thigvfpy  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(361)

oracle查询为-

select ROW_NUMBER () OVER(order by shortunitdesc) as SLNO, 
om.shortunitdesc,oc.operparam as Parameter, 
oc.tagno,oc.severity,lowlimit,highlimit, oc.operrange, IMPLICATION, DURATION from  oeconfig oc, oeunitmaster om 
where oc.unitcode = om.unitcode;

我想在mysql中转换,所以我尝试了

select @i:=@i+1 as slno, om.shortunitdesc, oc.operparam as Parameter, 
oc.tagno,oc.severity,oc.lowlimit,oc.highlimit,oc.operrange , IMPLICATION, DURATION 
from oeconfig oc oeunitmaster om , (select @i := 0) 
where oc.unitcode = om.unitcode 
order by shortunitdesc;

但它给出了一个错误-每个派生表都必须有自己的别名

nukf8bse

nukf8bse1#

select @i:=@i+1 as slno, om.shortunitdesc, oc.operparam as Parameter, 
oc.tagno,oc.severity,oc.lowlimit,oc.highlimit,oc.operrange , IMPLICATION, DURATION 
from oeconfig oc, oeunitmaster om, (select @i := 0) t
where oc.unitcode = om.unitcode 
order by shortunitdesc;

相关问题