Advertisement
Infernale

Longest/Shortest Distance [NCTU Floor 26]

Dec 21st, 2019
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 0.52 KB | None | 0 0
  1. /*Format : LIMIT a - 1, b - (a - 1)
  2.   ROUND(lat/lon, n)
  3.   ORDER BY city DESC(ra) OR ASC(al)
  4. */
  5. SELECT ROUND(MAX(SQRT(POW(x1 - x2, 2) + POW(y1 - y2, 2))), 4),
  6.        ROUND(MIN(SQRT(POW(x1 - x2, 2) + POW(y1 - y2, 2))), 4)
  7.     FROM ((SELECT id, ROUND(lat, 3) x1, ROUND(lon, 3) y1
  8.             FROM citytable GROUP BY x1, y1 ORDER BY city DESC, id LIMIT 5, 9) AS tt1
  9.                 JOIN
  10.          (SELECT id, ROUND(lat, 3) x2, ROUND(lon, 3) y2
  11.             FROM citytable GROUP BY x2, y2 ORDER BY city DESC, id LIMIT 5, 9) AS tt2
  12.                 ON tt1.id<>tt2.id AND tt1.id<tt2.id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement