SELECT *
FROM (SELECT ROUND (SUM (str_rol)) str_rol, unt_cod,
DECODE (unt_cod,
17, dpt_cod,
DECODE (dpt_cod, 8, 7, dpt_cod)
) dpt_cod,
dsg_cod, 4 sft_cod,
DECODE (cat_cod, 1, 'PM', 2, 'DW') cat_des
FROM sal.apr_str_01
WHERE TRUNC (:p_too_dte) BETWEEN str_frm_dte
AND DECODE (str_too_dte,
NULL, TRUNC (SYSDATE),
str_too_dte
)
AND cat_cod = 2
GROUP BY unt_cod,
DECODE (unt_cod,
17, dpt_cod,
DECODE (dpt_cod, 8, 7, dpt_cod)
),
dsg_cod,
DECODE (cat_cod, 1, 'PM', 2, 'DW')) apr_str
FULL OUTER JOIN
(SELECT COUNT (*) act_emp, emp_fil.unt_cod,
DECODE (unt_cod,
17, emp_fil.dpt_cod,
DECODE (emp_fil.dpt_cod, 8, 7, emp_fil.dpt_cod)
) dpt_cod,
emp_fil.dsg_cod
FROM sal.emp_fil_veu emp_fil
WHERE TRUNC (:p_too_dte) BETWEEN unt_frm_dte AND unt_too_dte
AND TRUNC (:p_too_dte) BETWEEN sft_frm_dte AND sft_too_dte
AND TRUNC (:p_too_dte) BETWEEN dsg_frm_dte AND dsg_too_dte
AND TRUNC (:p_too_dte) BETWEEN rst_frm_dte AND rst_too_dte
AND rsg_dte IS NULL
AND cat_cod = 2
AND (emp_fil.emp_cod, emp_fil.bas_cod) NOT IN (
SELECT emp_cod, bas_cod
FROM sal.not_ent_01
WHERE rin_dte IS NULL
AND ap_id IS NOT NULL)
AND (emp_fil.emp_cod, emp_fil.bas_cod) NOT IN (
SELECT emp_cod, bas_cod
FROM sal.not_ent_01
WHERE rin_dte IS NOT NULL
AND ap_id IS NULL)
GROUP BY emp_fil.unt_cod,
DECODE (unt_cod,
17, emp_fil.dpt_cod,
DECODE (emp_fil.dpt_cod, 8, 7, emp_fil.dpt_cod)
),
emp_fil.dsg_cod) act_str
ON ( apr_str.unt_cod = act_str.unt_cod
AND apr_str.dpt_cod = act_str.dpt_cod
AND apr_str.dsg_cod = act_str.dsg_cod
)