I will rephrase my question with a better example, then aks my question:-
In the example below, we take the employee name (ename) and the department number (deptno) and display the salary of the employee by their department.
SELECT * FROM
(SELECT
ename,
sum(decode(deptno,10,sal)) DEPT10,
sum(decode(deptno,20,sal)) DEPT20,
sum(decode(deptno,30,sal)) DEPT30,
sum(decode(deptno,40,sal)) DEPT40
FROM emp
GROUP BY ename)
ORDER BY 1;
The expected result would be as sampled below:-
ENAME DEPT10 DEPT20 DEPT30 DEPT40
---------- ---------- ---------- ---------- ----------
ADAMS 1100
ALLEN 1600
BLAKE 2850
CLARK 2450
..........etc
I would wish to make the Select a dynamic one, with resepect to the departments i.e. I envisage a situation where the Departments increase for example, or are merged for that matter, in which case now my Decode will no longer be accurate. Can I do a Select that has dynamic columns for the departments??
Let me know if you need more information.
Thanks.
In the example below, we take the employee name (ename) and the department number (deptno) and display the salary of the employee by their department.
SELECT * FROM
(SELECT
ename,
sum(decode(deptno,10,sal)) DEPT10,
sum(decode(deptno,20,sal)) DEPT20,
sum(decode(deptno,30,sal)) DEPT30,
sum(decode(deptno,40,sal)) DEPT40
FROM emp
GROUP BY ename)
ORDER BY 1;
The expected result would be as sampled below:-
ENAME DEPT10 DEPT20 DEPT30 DEPT40
---------- ---------- ---------- ---------- ----------
ADAMS 1100
ALLEN 1600
BLAKE 2850
CLARK 2450
..........etc
I would wish to make the Select a dynamic one, with resepect to the departments i.e. I envisage a situation where the Departments increase for example, or are merged for that matter, in which case now my Decode will no longer be accurate. Can I do a Select that has dynamic columns for the departments??
Let me know if you need more information.
Thanks.