Consecutive Numbers
You can achieve this result by using the LEAD
and LAG
window functions to compare the current row with the previous and next rows. The following query demonstrates how to do this:
|
|
This query first creates a derived table with the LEAD
and LAG
functions to get the values of the previous two rows. Then, it filters the derived table to rows where the current row, previous row, and next-to-previous row all have the same value, and returns the distinct values that meet this criteria.