Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

HOW TO FIND MEDIAN IN SQL FOR BOTH IDD AND EVEN

/*
HACKER RANK MYSQL SOLUTION.
*/
SET @rowindex := -1;
 
SELECT
   ROUND(AVG(N.LAT_N),4)
FROM
   (SELECT @rowindex:=@rowindex + 1 AS rowindex,
           STATION.LAT_N AS LAT_N
    FROM STATION
    ORDER BY STATION.LAT_N) AS N
WHERE
N.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));
 
PREVIOUS NEXT
Tagged: #HOW #TO #FIND #MEDIAN #IN #SQL #FOR #BOTH #IDD #AND #EVEN
ADD COMMENT
Topic
Name
8+7 =