Sort 1051 Discussions, By:
Please Login in order to post a comment
Note to the respected moderators: the problem statement is not clear at all and is quite confusing.
Select round(long_w,4) from Station where lat_n < 137.2345 order by lat_n desc limit 1;
From my HackerRank solutions.
SELECT ROUND(LONG_W, 4)
WHERE LAT_N < 137.2345
ORDER BY LAT_N DESC
Let me know if you have any questions.
Most of the answers listed in this discussion have answers like this:
// Solution1 -- order by desc and select top
select * from
(select round(LONG_W,4) from STATION
order by LAT_N desc)
Is there anything worse about this pattern?
I would have thought ordering was more resource intensive than assigning a variable and seeking. Is there a reason not to do this?
// Solution 2 -- assign max_lat_n variable and seek
variable max_lat_n number;
exec select max(LAT_N) into :max_lat_n from STATION where LAT_N<137.2345;
select round(LONG_W,4) from STATION where LAT_N=:max_lat_n;
And does this subquery approach repeat the max() operation on every row?
// Solution 3 -- subquery the max() operation
select round(LONG_W,4) from STATION
where LAT_N=(select max(LAT_N) from STATION
select round (long_w,4) from station where lat_n = (select max(lat_n) from station where lat_n<137.2345);