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

标签 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;

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

最佳答案

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;

关于MySQL – 使用变量为每行生成行号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52620045/

相关文章:

php - 无法用php在mysql古兰经数据库中搜索阿拉伯语

java.lang.NumberFormatException : null java. lang.Integer.parseInt(来源未知)

MySQL手动id自增

mysql - 如何管理大型视频数据库?

mysql - MySQL中如何确定一组的第一个结果?

javascript - 如何使用 AJAX 将变量传递给 PHP?

mysql - 为什么 MySQL SELECT UNHEX(1) = :) (a smile)

php - 如果不存在则插入到表中并返回结果

mysql - 将 pandas Dataframe 或 numpy 数组导出到 MySQL

MySQL:从文件名导入时间戳