Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个大约 100 行的表,我希望每次都得到数字和数字之间的行,就像这样
如果`i=1`我想得到行`0 1 2 3 4`
如果`i=2`我想得到行`5 6 7 8 9`
如果`i=3`我想得到行`10 11 12 13 14`
也许我的最后一个值只需要 3 或 4 行而不是 5 我认为解决方案将是这样的
select * from question limit (i-1)*5 , i*5-1
但不起作用,因为我不知道如何在查询中使用变量,当我尝试 i=1 时它不起作用并且出现语法错误
第一个参数LIMIT是从零开始的行索引。第二个是行数。因此,如果您一直在寻找五行:
LIMIT
SELECT * FROM question LIMIT (i-1)*5 , 5
(您必须(i-1)*5使用用于构建查询的任何语言进行计算,并将实际数字传递给 MySQL)。
(i-1)*5