04pallav
9/13/2017 - 9:54 PM

MEDIAN IN SQL

MEDIAN IN SQL

SELECT x.val from data x, data y
GROUP BY x.val
HAVING SUM(SIGN(1-SIGN(y.val-x.val)))/COUNT(*) > .5
LIMIT 1


DATA IS TABLE NAME
VAL IS COLUMN NAME ON WHICH MEDIAN IS TO BE CALCULATED