返回mySQL的原始行号 [英] return mySQL original row number

查看:76
本文介绍了返回mySQL的原始行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取数据库中原始记录的row_number.有什么方法可以在mysql中检索记录的原始行号? 假设我的声明是

I want to get the row_number of the original record in the database. Is there any way to retrieve the original row number of a record in mysql? Suppose my statement is

select course_id from course where subject='finance';

此查询可以有多个记录.假设它们来自行号4、5、7、9和10.如何从查询中检索这些行号?

there can be multiple records for this query. Suppose they are from row numbers 4, 5, 7, 9 and 10. How can i retrieve these row_numbers from my query?

推荐答案

检查:使用MySQL,如何生成在表中包含记录索引的列?

SELECT  c.course_id, 
        @curRow := @curRow + 1 AS row_number
FROM    course c
JOIN    (SELECT @curRow := 0) r;

但是请注意,这是人为的,因为唯一的实际行号"将是您自己的主ID,并且当您更改ORDER子句时,每种人为方法都会更改行号

Do note however, this is artificial as the only real 'row number' would be your own primary ID, and every artificial method will change the row number when you change the ORDER clause

这篇关于返回mySQL的原始行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆