Una consulta genera un result set (tabla)
Una consulta puede generar :
-Dato (valor)
-Un registro(tupla)
-Una tabla (una columna o n columnas)
Una subconsulta es utilizar uno de los resultados en otra consulta
las subconsultas van en el where
where campo (operador realacional) consulta
<,>,=, <> ----------->la consulta debe dar un solo valor
campo in (subconsulta)-----------------> la subconsulta puede ser una columna o un valor
---listar empleados del dpart 20 que tienen tocayos en el 50
nombre in (select nombre from e where d=50)
-----Listar por departamentos cantidad empleados que hay y el departamento debe tener un empleados llamado jorge
>any
----Empleados con salario mayor a cualquier jefe
<=all
Cuando hay group by o funciones se usa having
having count (e.id)>x
inteligencia de negocio, arquitectura de software
select * from employees;
select e1.employee_id, e1.first_name from employees e1 where e1.salary> select
avg(d.manager_id)from ;
select e.department_id, e.employee_id, count( distinct e.employee_id) from employees e group by e.department_id, e.employee_id having count( distinct e.employee_id)>4
join departments d1 on e.employee_id=d1.
join departments d2 on e.department_id=;
---Mostrar empleados cuyo salario sea mayor a la mitad del maximo s
alario de la region el cual el trabaja
select * from employees e where e.sala;ry> select max(e2) from employees e2 ---
where q.region_id =r1.region_id
---subconsultas en el from
select nombre from (select e.employee_id as codigo , e.first_name as nombre from employees e where e.department_id=50);
select nombre from (select e.employee_id as codigo , e.first_name as nombre from employees e where e.department_id=50 )join departments d on d.manager_id=codigo ;
select nombre from (select e.employee_id , e.first_name as nombre from employees e where e.department_id=50 )join departments d on d.manager_id=employee_id ;
---- con alias
select nombre from ((select e.employee_id , e.first_name as nombre from employees e where e.department_id=50 )) M join departments d on d.manager_id=M.employee_id;
select Round((count(e.employee_id)/ total)*100 ) from employees e cross join (select count(*) total from employees ) group by e.department_id, total ;
----mostrar por departamento empleado que ams gana
select from (select max(e.salary ) , e.department_id ,m.department_id from employees e join employees m on m.department_id=e.department_id group by e.department_id, m.department_id) as ta
join employees n on ta.
inteligencia de negocio, arquitectura de software
select * from employees;
select e1.employee_id, e1.first_name from employees e1 where e1.salary> select
avg(d.manager_id)from ;
select e.department_id, e.employee_id, count( distinct e.employee_id) from employees e group by e.department_id, e.employee_id having count( distinct e.employee_id)>4
join departments d1 on e.employee_id=d1.
join departments d2 on e.department_id=;
---Mostrar empleados cuyo salario sea mayor a la mitad del maximo s
alario de la region el cual el trabaja
select * from employees e where e.sala;ry> select max(e2) from employees e2 ---
where q.region_id =r1.region_id
---subconsultas en el from
select nombre from (select e.employee_id as codigo , e.first_name as nombre from employees e where e.department_id=50);
select nombre from (select e.employee_id as codigo , e.first_name as nombre from employees e where e.department_id=50 )join departments d on d.manager_id=codigo ;
select nombre from (select e.employee_id , e.first_name as nombre from employees e where e.department_id=50 )join departments d on d.manager_id=employee_id ;
---- con alias
select nombre from ((select e.employee_id , e.first_name as nombre from employees e where e.department_id=50 )) M join departments d on d.manager_id=M.employee_id;
select Round((count(e.employee_id)/ total)*100 ) from employees e cross join (select count(*) total from employees ) group by e.department_id, total ;
----mostrar por departamento empleado que ams gana
select from (select max(e.salary ) , e.department_id ,m.department_id from employees e join employees m on m.department_id=e.department_id group by e.department_id, m.department_id) as ta
join employees n on ta.
No hay comentarios:
Publicar un comentario