mysql 排序后, 如何加上序列号?

mysql 排序后, 如何加上序列号?,第1张

select a.*,

(select count(*) from tbl where col<=a.col) as rownum

from tbl a

mysql 没有oracle里面的rownum函数,用这个sql可以模拟下,但是如果数据量大的话,可能执行很慢。

修改sql如下

select (@xh := @xh + 1) as xh, a.* from (select * from auto where level = 3) a, (select @xh := 0) x

结果如下


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/7153871.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-02
下一篇 2023-04-02

发表评论

登录后才能评论

评论列表(0条)

保存