I am trying to run the following query on an Oracle express edition database.
SELECT SIGHTING_ID, MAX(DISTANCE)
FROM
(
SELECT SIGHTING_ID,
SQRT(POWER(LATITUDE + 28, 2) + POWER(LONGITUDE - 151, 2)) AS DISTANCE
FROM SIGHTINGS
)
GROUP BY SIGHTING_ID;
The purpose of the query is to return The SIGHTING_ID and DISTANCE for the sighting with the maximum distance from the co-ords (-28, 151)
The description for the table SIGHTINGS is as follows
desc SIGHTINGS
Name Null? Type
----------------------------------------- -------- ----------------------------
SIGHTING_ID NOT NULL NUMBER
SPOTTER_ID NUMBER
BIRD_ID NUMBER
LATITUDE NUMBER
LONGITUDE NUMBER
SIGHTING_DATE DATE
DESCRIPTION VARCHAR2(255)
When I run the query instead of selecting the maximum distance it selects and shows the entire list of sightings and their respective distances. SIGHTINGS has a large amount of tuples but below is a small list of the current output
SIGHTING_ID MAX(DISTANCE)
----------- -------------
264172 2.01556444
264174 2.34029913
264180 2.87647354
264198 .637887137
264205 2.08568933
264211 .232594067
264215 2.34104677
264221 .75
264224 .148660687
264235 .684470598
My question is how do I make it so that the MAX aggregate function works so that it returns just the maximum distance and the respect SIGHTING_ID?