The result set is partitioned by LocationID and logically ordered by Quantity. Observe that solutions 494 and 495 contain the same amount. Given that they are tied, These are both of those ranked 1. Look into this Window Functions class that includes 218 interactive workouts masking ranking functions, analytics capabilities, https://schwabxchange.com