Closest Pair of Sensor Stations
Problem
An environmental network places sensor stations on a coordinate grid.
```
SensorStation
+--------+------+
| Column | Type |
+--------+------+
| east | int |
| north | int |
+--------+------+
(east, north) is the primary key; no two stations share a location.
```
Report the shortest straight-line (Euclidean) distance between any two distinct stations, rounded to 2 decimal places. Name the output column `nearest`.
The distance between (east1, north1) and (east2, north2) is sqrt((east1-east2)^2 + (north1-north2)^2).
Tables
Example rows — the live problem includes the full dataset.
| east | north |
|---|---|
| 2 | 3 |
| 5 | 7 |
| 2 | 4 |
Expected output
Your answer should return 1 row with the columns nearest.
Starter code (SQL)
SELECT *
FROM SensorStation;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock