Reputation: 301
i keep getting missing experssion error, but i cant see what i have done wrong?
DECLARE
lat NUMBER := -28;
lon NUMBER := 151;
BEGIN
SELECT
sighting_id
FROM
sightings
ORDER BY
sqrt(power(lat - latitude, 2) + power(lon - longitude, 2))
END;
Upvotes: 1
Views: 6507
Reputation: 21
Hacker rank solution:
SELECT ROUND(SQRT(POWER(MIN(LAT_N)-MAX(LAT_N),2) +
POWER(MIN(LONG_W)-MAX(LONG_W),2)),4)
FROM STATION;
Upvotes: 2
Reputation: 1269623
You have several errors in your query.
from
.long
, which is a reserved word (see here).limit
(not supported by Oracle).DESC
keyword should go after the key expression, not before. And for distances, usually ASC
is used, not DESC
.INTO
clause or some other place to put the results.Are you sure you want to use Oracle?
EDIT:
Start with a query that looks more like this:
WITH params as (
SELECT -28 as lat, 151 as lon
FROM dual
)
SELECT s.sighting_id
FROM params CROSS JOIN
sightings s
ORDER BY sqrt(power(lat - latitude, 2) + power(lon - longitude, 2))
FETCH FIRST 1 ROW ONLY; -- Note: this is in Oracle 12c+
Upvotes: 3