You can create symbol predicates that compare a row to a previous or subsequent row, using a LAG or LEAD operator.