Py学习  »  DATABASE

mysql_“使用变量为每行生成行号”

user • 6 年前 • 1424 次点击  

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;

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

Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/30477
 
1424 次点击  
文章 [ 1 ]  |  最新文章 6 年前