选择下一行和上一行数据 SQLite [英] Select Next and previous row data SQLite

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

问题描述

我想问一下选择8787"时如何获取下一个和上一个数据

I want to ask on how to get the next and previous data when I select the "8787"

这是表名称的示例数据:

This is the sample data on table Name:

NameId 不是自动编号.

NameId is not auto number.

NameID    RName
6767      Apple
8787      Hallow
8627      Orange

谢谢

推荐答案

要得到下一个ID,把不大的ID都扔掉,按ID排序表格,让下一个ID排在第一位,然后取只有这一条记录:

To get the next ID, throw away all IDs that are not larger, sort the table by the ID so that the next ID is the first one, then take only this one record:

SELECT *
FROM MyTable
WHERE NameID > 8787
ORDER BY NameID
LIMIT 1

与之前的 ID 类似:

Similar for the previous ID:

SELECT *
FROM MyTable
WHERE NameID < 8787
ORDER BY NameID DESC
LIMIT 1

这篇关于选择下一行和上一行数据 SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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