select avg(q1.amount) median
from (
select amount,rownum rownbr
from (select amount
from tablex
order by 1) q0
) q1,
(
select round(count(*)/2+.4) as lowval,
round(count(*)/2+.5) as highval
from tablex
) q2
where rownbr between q2.lowval and q2.highval
/
Explanation: Q0: will retrieve all the amount values from tablex and order them
Q1: will relist the values applying the row number to the list set, (we can't do this in one step).
Q2: will retrieve the low and high row number value for the count of rows retrieved.
If an odd # then you'll be looking for rows between 13 and 13 for example.
The whole mess then (2 amount values, or one) is averaged to compute the median.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.