Are you stuck with a database that does not offer analytic SQL facilities ? Never mind, you can use the following trivial
query can determine the median salary from the EMP table
SQL> select avg(sal) from
2 ( select x.sal
3 from scott.EMP x, scott.EMP y
4 group by x.sal
5 having sum(sign(1-sign(y.sal-x.sal))) in
6 ( trunc((count(*)+1)/2), trunc((count(*)+2)/2) ) );
AVG(SAL)
----------
1550
Of course, if that is basically gobbledygook to you (and it certainly is to me!)…well, you should check out Oracle’s cool Analytic SQL features here




Leave a reply to Jason Bucata Cancel reply