我正在尝试查找与其上方至少两个值相同的值。请看一下。
id number
1 2
2 6
3 7
4 7
5 7
6 1
7 2
8 4
9 7
所以在这种情况下,select会返回:
ID NUMBER
3 7
4 7
5 7
答案 0 :(得分:1)
您可以使用correlated subquery
在其他行中查找值SELECT *
FROM MyTable
WHERE number = (SELECT number
FROM MyTable AS T2
WHERE T2.id = MyTable.id - 1)
AND number = (SELECT number
FROM MyTable AS T2
WHERE T2.id = MyTable.id - 2);