SELECT last_name, first_name
FROM hr.employees e
WHERE EMPLOYEE_ID IN (select d.manager_id from hr.departments d where manager_id is not null )
AND employee_id in (select manager_id from hr.employees where months_between(sysdate,hir e_date) < 3.0)
ORDER BY last_name, first_name;
esta es la mas facil, selecciono nombres y apellidos, y filtro el employee_id para que sea igual una subconsulta donde obtengo todos los managers de empleados, y claro ademas filtro otra vez el employee_id para los empleados de menos de 3 meses
SELECT last_name,first_name
FROM hr.employees
WHERE employee_id in (select manager_id from hr.employees where (sysdate-hire_date < 90) )
ORDER BY last_name, first_name;
Todavia mas facil, filtro el employee_id eligiendo los manager_id de los empleados que tienen menos de 90 dias, recordemos que al restar dos fechas obtenemos el numero de dias entre las dos fechas
SELECT r.region_name,
p.country_id, p.country_name , count(e.employee_id) as total_empleados
,
count(e.employee_id)
/ (
select
count(j.employee_id) from HR.job_history j natural join hr.departments natural
join hr.locations x where x.country_id = p.country_id
) as COF
FROM hr.regions r
join hr.countries p on (r.region_id=p.region_id) join hr.locations l on
(l.country_id=p.country_id)
natural join hr.departments natural join hr.employees e
GROUP BY
r.region_name, p.country_id, p.country_name
Esta esta mas divertida, primero se hace la cascada de relaciones, desde regions, hasta employees, colocando alias a las tablas, se inicia normalmente, hasta el count, luego si te fijas, utilizo el campo de la consulta externa p.country para filtar la consulta interna, para sacar el coeficiente que pide, pues estamos agrupando por el country_id.
SELECT
d.department_id,d.department_name, count(e.employee_id) as Total_Empleados
,
avg(sysdate-e.hire_date) as DiasProm
, (select max( x.first_name) from hr.employees
x where x.department_id=d.department_id
AND (sysdate-x.hire_date) = ( select
max(sysdate-e2.hire_date) from hr.employees e2 where e2.DEPARTMENT_ID=d.department_id
)
) as Nombre,
(select max(
x.last_name) from hr.employees x where x.department_id=d.department_id
AND (sysdate-x.hire_date) = ( select
max(sysdate-e2.hire_date) from hr.employees e2 where
e2.DEPARTMENT_ID=d.department_id )
) as
Apellidos
FROM hr.departments d
join hr.employees e on (d.department_id=e.department_id)
GROUP BY
d.department_id, d.department_name ;
SELECT
d.department_id,d.department_name, count(e.employee_id) as Total_Empleados
,
avg(sysdate-e.hire_date) as DiasProm
, (select max( x.first_name) from hr.employees
x where x.department_id=d.department_id
AND (sysdate-x.hire_date) = ( select
max(sysdate-e2.hire_date) from hr.employees e2 where e2.DEPARTMENT_ID=d.department_id
)
) as Nombre,
(select max(
x.last_name) from hr.employees x where x.department_id=d.department_id
AND (sysdate-x.hire_date) = ( select
max(sysdate-e2.hire_date) from hr.employees e2 where
e2.DEPARTMENT_ID=d.department_id )
) as
Apellidos
FROM hr.departments d
join hr.employees e on (d.department_id=e.department_id)
GROUP BY
d.department_id, d.department_name ;
me gustaria que ustedes comenten esta consulta...
.
1 comentario:
estan bien fumadas las consultas jejeje
Publicar un comentario