Skip to content

Instantly share code, notes, and snippets.

@Sailias
Created July 6, 2012 02:37
Show Gist options
  • Save Sailias/3057737 to your computer and use it in GitHub Desktop.
Save Sailias/3057737 to your computer and use it in GitHub Desktop.
SELECT my_ships.id as ship_id, (
SELECT planets.id
FROM planets
WHERE id NOT IN(SELECT id FROM planets WHERE conqueror_id=2599)
ORDER BY SQRT(((planets.location_x::bigint+-my_ships.location_x::bigint)^2) + ((my_ships.location_y::bigint-planets.location_y::bigint)^2))
ASC OFFSET 0 LIMIT 1) as planet_id
FROM my_ships;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment