MySQL –使用变量为每一行生成行号

时间:2018-10-03 05:10:20

标签: mysql

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;

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

1 个答案:

答案 0 :(得分:0)

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;