the subselect is simply counting what # the current flight is
we're joining in the where on origin so we can get all the flights of the same origin.
we're using previous id < current id since the id table is more than likely an int column marked as identity (1,1) meaning when you insert that column automatically assigns the next available int to it.
So in total within the subselect, we're getting the # of previous flights, and adding 1 so we can show that the current flight is flight # 10 or 11 or 12 , etc , to the destination.
a more concrete example:
ID | origin | time
1 | AK | 0820
2 | AR | 0830
3 | AK | 0900
4 | AK | 0930
5 | AR | 0935
The select above would output the following:
AK - 1 - 1
AK - 3 - 2
AK - 4 - 3
AR - 2 - 1
AR - 5 - 2
this way we see the origins grouped together, their original ID, and the order of which they will be flying.