我正在尝试从具有如下数据的表中选择提供的 id 之前和之后的第 5 条记录。
我想到的是:select id-5, id+10 from devTable where id = 10 and stateCode = 'CA';
但是,考虑到 stateCode,这实际上并没有在提供的 id 之前和之后为您提供第 5 个 id,它似乎只是将 /sub 5 添加到提供的 id 中。你知道如何以正确的方式做到这一点吗?
期望的结果
supplied id = 10 and stateCode = CA
prev | next
2 | 16
supplied id = 9 and stateCode = NY
prev | next
NULL | NULL
数据
"id" | "stateCode"
-------------------
"1" "CA"
"2" "CA"
"3" "CA"
"4" "CA"
"5" "NY"
"6" "NY"
"7" "CA"
"8" "CA"
"9" "NY"
"10" "CA"
"11" "CA"
"12" "NY"
"13" "CA"
"14" "CA"
"15" "CA"
"16" "CA"