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 4
decimal places.
Input Format
The STATION
table is described as follows:
β μ£Όμ
μλ μ½λλ νμμΈ κ²½μ°μλ§ μ€λ₯ μμ΄ μΆλ ₯λ¨
SELECT ROUND(AVG(LAT_N), 4)
FROM
(SELECT LAT_N,
PERCENT_RANK() OVER(ORDER BY LAT_N) AS result FROM STATION) AS sub
WHERE result = 0.5;
π» μ λ΅
SET @indexnum = -1;
SELECT ROUND(AVG(LAT_N), 4) AS Median
FROM(
SELECT
@indexnum := @indexnum + 1 AS row_num,
LAT_N
FROM STATION
ORDER BY LAT_N ASC) AS sub
WHERE row_num IN (FLOOR(@indexnum / 2), CEIL(@indexnum / 2));
RANK() OVER(ORDER BY weight) AS result
ex) 90, 90, 85μΌ κ²½μ° 1λ±, 1λ±, 3λ±μΌλ‘ λνλ¨ (곡λ λ±μλ§νΌ 건λ λ)
DENSE_RANK() OVER(ORDER BY weight) AS result
ex) 90, 90, 85μΌ κ²½μ° 1λ±, 1λ±, 2λ±μΌλ‘ λνλ¨