从mysql表中选择特定的行 [英] Select specific row from mysql table

查看:160
本文介绍了从mysql表中选择特定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我需要一个与

Ideally I need a query that is equivalent to

select * from customer where row_number() = 3

但这是非法的.

我不能使用自动递增的字段.

row_number()是需要选择的行.

row_number() is the row that needs to be selected.

我该怎么办?

好吧,我使用iSql * plus进行练习,出于某些原因,使用limit和auto_increment是非法的.我最终创建了一个序列和一个触发器,每次输入一个条目时,ID都增加了1.

Well, I use iSql*plus to practice, and using limit and auto_increment is illegal for some reason. I ended up creating a sequence and a trigger and just upped the id by 1 every time there was an entry.

推荐答案

您可以使用LIMIT 2,1代替WHERE row_number() = 3.

文档所述,第一个参数指定以下内容的偏移量:第一行返回,第二行指定要返回的最大行数..

请记住,它是一个从0开始的索引.因此,如果需要行号 n ,则第一个参数应为 n-1 .第二个参数将始终为 1 ,因为您只需要一行.例如,如果要表customer的行号 56 :

Keep in mind that it's an 0-based index. So, if you want the line number n, the first argument should be n-1. The second argument will always be 1, because you just want one row. For example, if you want the line number 56 of a table customer:

SELECT * FROM customer LIMIT 55,1

这篇关于从mysql表中选择特定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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