给定像这样的表格设置
tableA {
id = 1
name = 'bob'
id = 2
name = 'sally'
id = 3
name = 'sue'
}
tableB {
id = 1
name = 'bob'
}
如果我运行此命令,它会返回 ID 2 和 3,正如我所希望的那样:
select id
from tableA a
left join tableB b using (id)
where id not in (select id from tableB)
order by id
limit 10;
但这是一个非常大的表,所以我需要使用偏移量。当我尝试以下命令时,没有返回任何结果。
select id
from tableA a
left join tableB b using (id)
where id not in (select id from tableB)
order by id
limit 10 offset 10;
使用连接时有没有办法使用偏移?
流程环境不可见,但我建议采用这种方法。您可以按批处理行(限制为 10)。
使用参数@startId=0
处理批次后,将@startId 作为处理批次中的最大值(id),并将其作为参数值,无下一个查询 - 无偏移。
例子