-- Problem: query the average salary of each department's position
And display it in a query
Idea: first, we will find out the three tables, assuming a B c, and then combine a B with each other.
There is no relationship between them, so to connect them, we need to use rownum to use the full outer join and rownum to make table a B in the form of fields (rather than rows) in this way, data in different tables can be merged in the form of columns (the reason is that the union all minus intersect combines multiple query results in the form of rows ). to Merge multiple query results in the form of columns, you need to use rownum and (completely) to solve this problem, the core is rownum and full outer connection.
Code:
Select e3. average department salary, e3. average position salary, e44. average department position salary from
(Select e11. average department salary, e22. average job salary, rownum rn from
(Select e1. average department salary, rownum rn from
(Select avg (sal) average salary from
Emp group bydeptno) e1) e11
Full join
(Select e2. average job salary, rownum rn from
(Select avg (sal) average job salary from
Emp group by job) e2) e22
On e11.rn = e22.rn) e3
Full join
(Select e4. *, rownum rn from
(Select avg (sal) average job salary from
Emp group by deptno, job) e4) e44
On e3.rn = e44.rn;