I've been trying to figure out a way to order a row after another based on the value of a column from the previous row. In my SQL query below, I first initially want to order the dataset by distance in ascending order. However
However, after that, I'd like to then check (on each row), whether the difference between the "distance" value of the previous row and the "distance" value of the current row is less than 50. If so, I'd then like to sort whichever row has highest "rating" value first.
Any help would be appreciated. Thanks