【发布时间】:2008-12-11 21:14:19
【问题描述】:
我有一个名为 faq_questions 的表,其结构如下:
id int not_null auto_increment,
question varchar(255),
sort_order int
我正在尝试构建一个给定排序顺序的查询,选择具有下一个最高排序顺序的行。
例子:
id question sort_order
1 'This is question 1' 10
2 'This is question 2' 9
3 'This is another' 8
4 'This is another one' 5
5 'This is yet another' 4
好的,假设我为已知的排序顺序(id 4)传入 5,我需要它返回 id 为 3 的行。由于无法保证 sort_order 是连续的,我不能只选择 known_sort_order + 1 .
谢谢!
【问题讨论】: