Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Help Simplifying SQL query
Hi there,
I'm new to SQL, only been working with a few months. I've created this query that does exactly what I need. However, it is very apparent that I can simplify it as I am reusing the same select statement code 3 times.
It seems I should be able place this select statement in the from statement once and then use an alias or something to access it earlier in the statement.
Any ideas on how to do this without using views?
Thanks in advance!
select emp_lname, emp_fname, dept_name, salary,
salary -
(select avg(salary) from sales2.employee e2
where dept_id=e.dept_id ) as Difference,
(select avg(salary) from sales2.employee e2
where dept_id=e.dept_id ) as AVERAGE
salary >
(select avg(salary) from sales2.employee e2
where dept_id=e.dept_id group by dept_id)
![]() |
![]() |