We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
I am using this query but getting error can anyone help
WITH sorted_lat AS (
SELECT lat_n FROM station ORDER BY lat_n ASC
),
counting AS (
SELECT COUNT(*) AS total_count FROM station
)
SELECT ROUND(
CASE
WHEN total_count % 2 != 0 THEN
(SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET total_count / 2)
ELSE
(
(SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET (total_count / 2) - 1) +
(SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET total_count / 2)
) / 2
END, 4
)
FROM counting;
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Weather Observation Station 19
You are viewing a single comment's thread. Return to all comments →
I am using this query but getting error can anyone help
WITH sorted_lat AS ( SELECT lat_n FROM station ORDER BY lat_n ASC ), counting AS ( SELECT COUNT(*) AS total_count FROM station ) SELECT ROUND( CASE WHEN total_count % 2 != 0 THEN (SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET total_count / 2) ELSE ( (SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET (total_count / 2) - 1) + (SELECT lat_n FROM sorted_lat LIMIT 1 OFFSET total_count / 2) ) / 2 END, 4 ) FROM counting;