25 February 2018

placesOfInterestPairs

My solution:
CREATE PROCEDURE placesOfInterestPairs() 
BEGIN 
  SELECT place1, 
         place2 
  FROM   (SELECT sights.name                          AS place1, 
                 sights2.name                         AS place2, 
                 SQRT(POW(sights.x - sights2.x, 2) 
                      + POW(sights.y - sights2.y, 2)) AS distance 
          FROM   sights, 
                 sights AS sights2 
          WHERE  sights.name < sights2.name) AS t 
  WHERE  distance < 5 
  ORDER  BY place1, 
            place2; 
END