Pairing animals together based on weight difference in SQL
You're given the following table showing the weights of various unique animals in a zoo:
Suppose we want to return a list of animal pairs that are within 100lbs of each other (inclusive). For example, we can see that animals with ID 9992 (weight 1040lbs) and 99929 (weight 1090lbs) are within 100lbs of each other, so that particular snippet would return:
Given this table/information, write a SQL query to return all the pairs of animals within 100lbs of each other. You can view/query the table in an interactive SQL fiddle here.
Subscribe to premium account to see the solution.Get premium now