我有一个每页显示10行的表。现在,给定一个项目的ID,我如何获得该项目所在的“页面”?
换句话说,我正在寻找给定记录ID的偏移量(10的倍数)。
SELECT * FROM items
WHERE category = "category"
LIMIT ?, 10 <----- TRYING TO FIGURE OUT HOW TO GET ? OFFSET GIVEN ID
ORDER BY id DESC
答案 0 :(得分:0)
这应该这样做;
SELECT 10*FLOOR(COUNT(id)/10) FROM items where id < YOUR_ID
答案 1 :(得分:0)
试试这个:
SET @rownum = 0;
Select sub.*, 10 * Floor(sub.rownum / 10) as pagenum
from
(
Select *, (@rownum:=@rownum+1) as rownum
from items order by id desc
) sub
where sub.ID = givenID;