hi,
i m only a novice in Oracle and i tried something similar to what your original query is.
i took the employees table of the HR schema which is created by default in Oracle when it is installed.
what i did is to list the job_id, last_name (maxSalary),last_name(minSalary)
i.e. list the job_id, last name of the person who earns the max salary in the department and also the last name of the person who earns the minimum salary in the department.
Code:
create table temptb1 as
(select egr.jd,e.last_name minimumSal,egr.mins from employees e,(select job_id jd,min(salary) mins,max(salary) maxs from employees group by job_id) egr
where e.job_id = egr.jd and e.salary = egr.mins)
create table temptb2 as
(select egr.jd,e.last_name maximumSal,egr.maxs from employees e,(select job_id jd,min(salary) mins,max(salary) maxs from employees group by job_id) egr
where e.job_id = egr.jd and e.salary = egr.maxs)
select t1.jd, t1.MINIMUMSAL, t2.MAXIMUMSAL from temptb1 t1,temptb2 t2 where t1.jd=t2.jd;
i created two tables, one to list the job_id and the lastname of the person who earns the minimum salary in the department and another table to list the job_id and the lastname of the person who earns the max salary in the department.
later another query to do a simple join.
similarly you can try to create a couple of global temporary tables may be.
i dont know whether this helps. if it does gr8.
thanks
added: or creating two views mite also help