Shortest Distance in a Plane
Problem
Point2D(x, y). Return the shortest distance between any two distinct points (rounded to 2 dp).
Input
p=[(-1,-1),(0,0),(-1,-2)]Output
1.00(-1,-1) to (-1,-2) is the closest pair.
SELECT ROUND(MIN(SQRT(POW(a.x - b.x, 2) + POW(a.y - b.y, 2))), 2) AS shortest
FROM Point2D a JOIN Point2D b ON (a.x, a.y) <> (b.x, b.y);
Explanation
This is the 2D version of the closest-pair idea: self-join the points so every pair shows up, measure the straight-line distance for each pair, and keep the smallest.
The join condition (a.x, a.y) <> (b.x, b.y) keeps every pairing where the two points are different, so a point is never compared with itself.
For each pair we use the Euclidean distance formula SQRT(POW(a.x-b.x, 2) + POW(a.y-b.y, 2)), then MIN(...) grabs the closest pair and ROUND(..., 2) trims it to two decimals.
Example: with points (-1,-1), (0,0), (-1,-2), the pair (-1,-1) and (-1,-2) are distance 1.00 apart, which beats the others (about 1.41 and 2.24), so the answer is 1.00.