Database Reference
In-Depth Information
Tableau 4-14 : Calcul des effectifs
Vue monotable
Résultat
CREATE VIEW soutou.v_job_emps
(n_dept, id_emploi, effectif)
AS SELECT department_id, job_id,
COUNT(employee_id)
FROM hr.employees
WHERE department_id IS NOT NULL
GROUP BY department_id, job_id
ORDER BY 1;
SQL> SELECT n_dept, id_emploi, effectif
FROM soutou.v_job_emps;
N_DEPT ID_EMPLOI
EFFECTIF
---------- ----------
------------
10 AD_ASST
1
20 MK_MAN 1
20 MK_REP
1
30 PU_CLERK
5
30 PU_MAN 1
40 HR_REP 1
50 SH_CLERK
20
50 ST_CLERK
20
50 ST_MAN 5
60 IT_PROG
5
70 PR_REP
1
80 SA_MAN 5
80 SA_REP 29
90 AD_PRES 1
90 AD_VP
2
100 FI_ACCOUNT
5
100 FI_MGR
1
110 AC_ACCOUNT
1
110 AC_MGR
1
La deuxième vue joint ces effectifs pour extraire le salaire médian de chaque type d'emploi. Il
s'agit ici d'une vue complexe interrogeant conjointement une table et une autre vue.
Tableau 4-15 : Jointure avec les salaires médians
Vue complexe d'une vue
Résultat
CREATE VIEW soutou.v_v_job_emps
(n_dept, id_emploi, effectif, montant)
AS SELECT v_j.n_dept, v_j.id_emploi,
effectif,
(j.max_salary-j.min_salary)
FROM soutou.v_job_emps v_j, hr.jobs j
WHERE v_j.id_emploi = j.job_id
ORDER BY 1;
SQL> SELECT n_dept, id_emploi, effectif, montant
FROM soutou.v_v_job_emps;
N_DEPT
ID_EMPLOI
EFFECTIF
MONTANT
---------- ----------
----------- -----------
10 AD_ASST 1 3000
20 MK_MAN
1 6000
20 MK_REP 1 5000