Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: A VERY DIFFICULT QUERY
> I want a sql query for the following result:
> From a table containing salaries (say emp table)
> I want the salary which is closest to the average of all the
> salaries
Try this :
SELECT salary from
(select avg(salary) "AVG" from salaries),salaries
where abs(AVG-salary)=(select min(abs(AVG-salary)) from salaries)