您好,很高興為您解答。
方法壹:
查詢上壹條記錄的SQL語句(如果有其他的查詢條件記得加上other_conditions以免出現不必要的錯誤):
select?*?from?table_a?where?id?=?(select?id?from?table_a?where?id?<?{$id}?[and?other_conditions]?order?by?id?desc?limit?1)?[and?other_conditions];查詢下壹條記錄的SQL語句(如果有其他的查詢條件記得加上other_conditions以免出現不必要的錯誤):
select?*?from?table_a?where?id?=?(select?id?from?table_a?where?id?>?{$id}?[and?other_conditions]?order?by?id?asc?limit?1)?[and?other_conditions];方法二:
查詢上壹條記錄的SQL語句((如果有其他的查詢條件記得加上other_conditions以免出現不必要的錯誤))
select?*?from?table_a?where?id?=?(select?max(id)?from?table_a?where?id?<?{$id}?[and?other_conditions])?[and?other_conditions];查詢下壹條記錄的SQL語句(如果有其他的查詢條件記得加上other_conditions以免出現不必要的錯誤):
select?*?from?table_a?where?id?=?(select?min(id)?from?table_a?where?id?>?{$id}?[and?other_conditions])?[and?other_conditions];如若滿意,請點擊右側采納答案,如若還有問題,請點擊追問
希望我的回答對您有所幫助,望采納!
~?O(∩_∩)O~