Mysql 选择带有偏移量的记录 [英] Mysql select records with offset

查看:50
本文介绍了Mysql 选择带有偏移量的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一个 mysql select,它允许我在前几场比赛的数量发生变化后选择(LIMIT 8)条记录;

I'm looking for a mysql select that will allow me to select (LIMIT 8) records after some changing number of first few matches;

select id
from customers
where name LIKE "John%"
Limit 8

所以,如果我有一张桌子,里面有 1000 名不同姓氏的约翰我希望能够选择记录 500-508

So if i have a table with 1000 of johns with various last names I want to be able to select records 500-508

推荐答案

你可以把偏移量发送到limit语句中,像这样:

You can send the offset to the limit statement, like this:

SELECT id 
FROM customers 
WHERE name LIKE "John%" 
LIMIT 8 OFFSET 500

注意限制上的 OFFSET 500.这将起点"设置为前 500 个条目(在条目 #501 处).

Notice the OFFSET 500 on the limit. That sets the 'start point' past the first 500 entries (at entry #501).

因此,将选择条目 #501、#502、#503、#504、#505、#506、#507 和 #508.

Therefor, entries #501, #502, #503, #504, #505, #506, #507 and #508 will be selected.

这也可以写成:

LIMIT 500, 8

就我个人而言,我不太喜欢那样,也不了解顺序.

Personally, I don't like that as much and don't understand the order.

迂腐点:500-508是9个条目,所以我不得不调整.

Pedantic point: 500-508 is 9 entries, so I had to adjust.

这篇关于Mysql 选择带有偏移量的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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