MySQL-记录集中的行号? [英] MySQL - row number in recordset?

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

问题描述

首先,我不问结果返回给您后如何获取当前行号.

First of all, I'm not asking how to get the current row number after the results have been return to you.

我想知道,是否有可能将行号作为MySQL结果中返回的列之一?我想做的是添加一个数字,以递增到每一行.像这样:

I'm wondering, is it possible to get the row number as one of the returned columns in MySQL results? What I'm trying to do is to add a number to increments up to every single row. Like this:

| id | myNum | name |
+----+-------+------+
| 34 |     1 | John |
| 24 |     2 | Alex |
| 56 |     3 | Brad |
etc...

我猜想它会涉及存储过程,但是我想知道如果没有它们,是否有可能...

I'm guessing it would involve stored procedures, but I'm wondering if it's possible without them...

推荐答案

select table.*,@rn:=@rn+1 as row_num
from table,(select @rn:=0) as r order by field_you_like

这篇关于MySQL-记录集中的行号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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