How should I write query for this? Consider P1(a, b) and P2(c, d) to be two points on a 2D plane.
a happens to equal the minimum value in Northern Latitude (LAT_N in STATION)
b happens to equal the maximum value in Northern Latitude (LAT_N in STATION)
c happens to equal the minimum value in Western Longitude (LONG_W in STATION)
d happens to equal the maximum value in Western Longitude (LONG_W in STATION)
Query the Manhattan Distance/Eculids Distance between points P1 and P2 and round it to a scale of 4 decimal places.
Table STATION(ID number, CITY varchar2(21), STATE varchar2(2), LAT_N number, LONG_W number)
any idea will be appreciated
Easiest way of doing this problem is Using mathematics function [ Dis. = sqrt((x2−x1)^2+(y2−y1)^2) ], try: for sql server: for Manhattan Distance:
select format(abs(min(LAT_N)-max(LAT_N))+abs(min(long_w)-max(long_w)),'.####') from station;
And for Eculids Distance:
select format(sqrt(square(min(LAT_N)-max(LAT_N))+square(min(long_w)-max(long_w))),'.####') from station;