Funciones de grupos
AVG Promedio
COUNT Cuenta cantidad de registros
MAX Obtiene valor máximo
MIN “” valor mínimo de un grupo de datos.
SUM Para realizar las sumas.
Select AVG(salary),MAX(salary), MIN(salary, SUM(salary)
-------------------------------------------------
From s_emp
Select dept_id, AVG(salary)
From s_emp
-------------------------------------------------
Groupby dept_id
-------------------------------------------------
Having Es como una where, pero como un where de grupo
-------------------------------------------------
Select dept_id, AVG(salary)From s_emp
Group by dept_id
-------------------------------------------------
Having AVG(salary) > 1000
-------------------------------------------------
Mostrar la cantidad de empleadospor cargo de los departamentos 42 y 44.
select e.title, count(e.id)
from s_emp e, s_dept d
where e.dept_id = d.id and
e.dept_id = 42 or d.id = 44-------------------------------------------------
group by e.title
-------------------------------------------------
* INSERT INTO TABLA VALUES (…………….)
* INSERT INTO TABLA
SELECT ……
* PRACTICAS EN AULA:
INSERT INTO S_DEPTVALUES (2,'CONTA',1)
SELECT *FROM S_DEPT
UPDATE S_DEPT SET NAME = 'CONTABILIDAD'
WHERE ID = 2
DELETE S_DEPT
WHERE ID = 2
* Oracle tiene base de datos transaccionales
* COMMIT* ROOLBACK
PL – SQL
* SELECT campo1 INTO var1 INTO ES PARA SOLO UN DATO
From
Where
Having
.
.
“Cursores” – ya no se utiliza el INTO – Y TAMBIEN UN “FOR”
Solo es necesario estopara el “SELECT”
* IF THEN ELSE
* IF condición
THEN instrucciones
ELSE instrucciones
END IF;
Ej.
IF total > 100
THEN suma1 := suma1 + total;
ELSE suma1 := suma1 – total;END IF;
* WHILE condición
LOOP instrucciones
END LOOP;
* FOR nombre_variable
IN valor inicial .. valor_final
LOOP instrucciones…
END LOOP
DEFINICION DE VARIABLES Nombre_de_la...
Regístrate para leer el documento completo.