Find median in mysql

23 views Asked by At

I am trying to solve the question on HackerRank named Weather Observation Station 20, which you can find here which states:

A median is defined as a number separating the higher half of a data set from the lower half. Query the median of the Northern Latitudes (LAT_N) from STATION and round your answer to decimal places.

The STATION table is described as follows:

I am trying to submit this query as an answer:

SELECT ROUND(LAT_N, 4) 
FROM STATION 
ORDER BY LAT_N 
LIMIT 1 
OFFSET FLOOR((SELECT COUNT(LAT_N) FROM STATION)/2);`

where I am trying to locate the centre value. And for this query I am facing this error:

ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(SELECT FLOOR((SELECT COUNT(LAT_N) FROM STATION)/2))' at line 5

I am not sure what is the cause of error here.

0

There are 0 answers