Está en la página 1de 4

-- mas vendido

select *
from (
select pi.product_name, max(oi.quantity)
from order_items oi, product_information pi
where oi.product_id= pi.product_id
group by pi.product_name
order by 2 desc
)
where rownum<=1
-- mas solicitado
select *
from (
select pi.product_name, count(oi.product_id)
from order_items oi, product_information pi
where oi.product_id= pi.product_id
group by pi.product_name
order by 2 desc
)
where rownum<=1

-- Crear una copia de la tabla empleados,


-- sin el campo department_id.

create table empleados as select


EMPLOYEE_ID,FIRST_NAME,LAST_NAME
,EMAIL,PHONE_NUMBER,HIRE_DATE,JOB_ID,SALARY,COMMISSION_PCT,MANAGER_ID
from employees
Where department_id<80 OR
MANAGER_ID IS null;

select * from empleados

--Realizar una inserci�n selectiva a la


--tabla empleados utilizando la fecha del sistema.
INSERT INTO empleados (employee_id,
first_name, last_name,
email, phone_number, hire_date, job_id,
salary, commission_pct)
VALUES (555,'Roberto','Perea',
'rp@yahoo.com','185.851.8584',
SYSDATE, 'AC_ACCOUNT', 9900, null);

commit

select * from empleados


where employee_id=555

delete from empleados


where employee_id=555

commit

--Ahora inserte valores por defecto,


--definidos al crear la base de datos.

INSERT INTO empleados (employee_id,


first_name, last_name, email,
phone_number, hire_date, job_id,
salary, commission_pct,MANAGER_ID)
VALUES (556,'Roberta', 'Perea',
'rp@yahoo.com', '185.851.8584',
SYSDATE, 'AC_ACCOUNT', 8900, null,
DEFAULT);

--consulte el registro insertado. Existe


--alguna diferencia en los datos
--insertados en los dos registros
--anteriores.
/* utiliza el valor por defecto definido en la tabla */

ALTER TABLE empleados MODIFY manager_id DEFAULT 100;


--Ejecute el insert que incluye el campo
--manager_id el valor asignado por
--defecto.

INSERT INTO empleados (employee_id,


first_name, last_name, email,
phone_number, hire_date, job_id,
salary, commission_pct,MANAGER_ID)
VALUES (557,�Luisa', 'Perea',
'rp@yahoo.com', '185.851.8584',
SYSDATE, 'AC_ACCOUNT', 10000, null,
DEFAULT);

--Actualizar el salario y el trabajo del empleado


--192. Ahora el trabajo es igual al empleado 180
--e igual al salario del empleado 143.
UPDATE empleados
SET job_id = (SELECT job_id
FROM empleados
WHERE employee_id = 180),
salary = (SELECT salary
FROM empleados
WHERE employee_id = 143)
WHERE employee_id = 192;

--INSERCION INCONDICIONAL
Create table historico_salario (Empid number,Hiredate date, Sal number);
select * from historico_salario

Create table historico_sal_jefes (Empid


number,mgr number, Sal number);
select * from historico_sal_jefes

INSERT ALL
INTO historico_salario
VALUES(EMPID,HIREDATE,SAL)
INTO historico_sal_jefes
VALUES(EMPID,MGR,SAL)
SELECT employee_id EMPID, hire_date
HIREDATE, salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;

select * from historico_salario


select * from historico_sal_jefes
truncate table historico_salario
truncate table historico_sal_jefes

INSERT ALL
WHEN SAL > 10000 THEN
INTO historico_salario
VALUES(EMPID,HIREDATE,SAL)
WHEN MGR > 200 THEN
INTO historico_sal_jefes
VALUES(EMPID,MGR,SAL)
SELECT employee_id EMPID,hire_date
HIREDATE,salary SAL, manager_id MGR
FROM employees
WHERE employee_id > 200;

select * from historico_salario


select * from historico_sal_jefes

select * from employees


WHERE employee_id > 200

Create table salario_especial(Deptid number,


Sal number);

select * from salario_especial

Create table historico_fecha_inicial_00(Deptid


number,Hiredate date);

select * from historico_fecha_inicial_00

Create table historico_fecha_inicial_99(


Deptid number,Hiredate date);

Create table historico_fecha_inicial(Deptid


number, Hiredate date);

INSERT FIRST
WHEN SAL > 25000 THEN
INTO salario_especial VALUES(DEPTID, SAL)
WHEN HIREDATE like ('%00%') THEN
INTO historico_fecha_inicial_00
VALUES(DEPTID,HIREDATE)
WHEN HIREDATE like ('%99%') THEN
INTO historico_fecha_inicial_99 VALUES(DEPTID,HIREDATE)
ELSE
INTO historico_fecha_inicial VALUES(DEPTID,
HIREDATE) SELECT department_id DEPTID, employee_id,salary SAL, hire_date
HIREDATE
FROM empleados
where salary >10000;

select * from salario_especial


select * from historico_fecha_inicial_00
truncate table historico_fecha_inicial_00
truncate table historico_fecha_inicial_99
truncate table salario_especial

where hiredate like ('%00%')


select * from historico_fecha_inicial_99
select * from historico_fecha_inicial

select salary
from empleados
where

update empleados set hire_date='08-06-00'


where employee_id = 114
commit

select * from empleados


where hire_date like ('%00%')

SELECT employee_id,salary SAL, hire_date HIREDATE


FROM empleados
where salary >10000

--Inserci�n por pivoteo


Create table ventas_datos(
EMPLOYEE_ID number,
semana_ID number,
ventas_lun number,
ventas_mar number,
ventas_mie number,
ventas_jue number,
ventas_vie number);

Create table ventas_INFO (


Employee_id number,
semana number,
ventas number);
Insert into ventas_datos
values
(2100,1,1000000,2000000,3000000,4000000,5
000000);

/******************* TRANSACCIONES
*****************************************************/

pendiente

/******************** crear objetos dbnomina

/*************** CONSULTA APARTE PARA VER COSAS DEL DICCIONARIO DE DATOS


**************/
select owner,constraint_name,table_name,constraint_type
from dba_constraints
where owner='HR

SELECT * FROM DBA_TABLES


WHERE OWNER = 'HR'

También podría gustarte