Created
July 5, 2012 13:12
-
-
Save santiagobasulto/3053583 to your computer and use it in GitHub Desktop.
Ranking queries
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- Query 1 | |
| SELECT id, distance_in_meters from stats_workout s1 | |
| WHERE distance_in_meters > (SELECT distance_in_meters FROM stats_workout WHERE id=3) | |
| ORDER BY distance_in_meters DESC; | |
| -- Query 2 | |
| SELECT DISTINCT s1.id, s1.distance_in_meters from stats_workout s1 | |
| JOIN stats_workout s2 ON (s1.distance_in_meters > s2.distance_in_meters) | |
| WHERE s2.id = 3 | |
| ORDER BY s1.distance_in_meters DESC; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment