mysql 按部分选择,如何克服记录间隙?
这是我的场景: 我有超过100,000条记录,以varchar id为主键,但id不连续:有间隙,例如1,2,3...2000, 3500,3501,3502.... 我需要分部分查询这个表,每部分有1000条记录,但是sql有问题: select * from mytable where rec_id 介于 1 到 1000 之间 如果查询落入间隙(2000 - 3500),它将不会返回任何内容,但是我如何知道表是否已完成或查询只是在间隙中?
无论如何,如果您有任何其他解决方案,请与我分享,谢谢
here is my scenario:
i have over 100,000 records, with varchar id as the primary key, but the id is not continuous: there is a gap, like 1,2,3...2000, 3500,3501,3502....
i need to query this table by sections, each with 1000 records, but there is a problem with the sql:
select * from mytable where rec_id between 1 and 1000
if the query fell into the gap (2000 -- 3500), it will return nothing, but how do i get to know that if the table is finished or the query is just in the gap?
and by all means, if you have any other solutions, please share with me, thx
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,请使用
limit
和offset
:此查询将返回前 1000 个寄存器:
此查询将返回从 1001 到 2000 的寄存器:
依此类推。
Use
limit
andoffset
for this purpose:This query will return the first 1000 registers:
This one will return registers from 1001 to 2000:
and so on.