7.10 计算中间值

问题:计算一列数字值的中间值(中间值就是一组有序元素中间成员的值)。例如,查找DEPTNO 20中工资的中间数。

select avg(sal) 
from (
select e.sal 
from emp e,emp d
where e.deptno = d.deptno and e.deptno =20
group by e.sal
having sum(case when e.sal=d.sal then 1 ehse 0 end) >=abs(sum(sign(e.sal - d.sal))));

原文地址:https://www.cnblogs.com/l10n/p/7523280.html