如何根据某个值从数据库中获取对象及其后继对象?
更具体地说,我有一张table articles
带列 id
, name
, order
. 我想用特定的 order
以及它的继任者 order
价值观。我的查询应该是什么样的?
例子
数据:
id name order
1 A 14
2 B 27
3 C 18
4 D 86
5 E 39
6 F 2
提问:
FetchTwoByOrderASC(18) => (C,B) // 18 is C and the successor of 18 in this case is 28 which is B --> {(F,2)-(A,14)-(C,18)-(B,27)-(E,39)-(D,86)}
FetchTwoByOrderASC(39) => (E,D) // 39 is E and the successor of 39 in this case is 86 which is D --> {(F,2)-(A,14)-(C,18)-(B,27)-(E,39)-(D,86)}
FetchTwoByOrderASC(14) => (A,C) // 14 is A and the successor of 14 in this case is 18 which is C --> {(F,2)-(A,14)-(C,18)-(B,27)-(E,39)-(D,86)}
我使用mysql数据库。
1条答案
按热度按时间lfapxunr1#
或者