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.
Weather Observation Station 20
Weather Observation Station 20
Sort by
recency
|
3711 Discussions
|
Please Login in order to post a comment
WITH CTE as ( Select LAT_N, ABS(ROW_NUMBER() OVER (Order By LAT_N) - ROW_NUMBER() OVER (Order By LAT_N desc)) ROW# FROM STATION)
Select CAST(AVG(LAT_N) as decimal(38,4)) from CTE WHERE ROW# in (Select MIN(ROW#) From CTE);
Here's my solution ... please share your thoughts ...
WITH RankedStations AS ( SELECT LAT_N, ROW_NUMBER() OVER (ORDER BY LAT_N) AS RowAsc, ROW_NUMBER() OVER (ORDER BY LAT_N DESC) AS RowDesc FROM STATION ) SELECT ROUND( AVG(LAT_N), 4 ) AS median FROM RankedStations WHERE RowAsc = RowDesc OR RowAsc + 1 = RowDesc;
SELECT CAST(ROUND(AVG(LAT_N),4) AS DECIMAL(10,4)) AS median FROM ( SELECT LAT_N, ROW_NUMBER() OVER (ORDER BY LAT_N) AS row_num, COUNT(*) OVER () AS total_count FROM STATION ) AS ranked_data WHERE row_num = (total_count + 1) / 2;