Sei sulla pagina 1di 4

//////////////////////// // Jhonny Taborda ///////////////////////// create table Categoria ( cat_id pel_id cat_nombre cat_descripcion constraint PK_cat_id ); create table

Pelicula ( pel_id integer not null, pel_nombre VARCHAR(40) not null, pel_resumen VARCHAR(500) not null, pel_duracion timestamp, constraint PK_pelicula primary key (pel_id) ); create table Actua ( actu_id integer not null, pel_id integer not null, act_id integer not null, numcontrato integer not null, salario float, constraint PK_actua primary key (actu_id) ); create table pais ( pai_id integer not null, pai_nombre varchar(30) not null, constraint PK_pais primary key (pai_id) ); create table representante ( rep_id integer not null, rep_nombre varchar(40) not rep_mail varchar(40) not rep_oficina varchar(15) not constraint PK_representante );

INTEGER not null, INTEGER not null, VARCHAR(40) not null, VARCHAR(40), primary key (cat_id)

null, null, null, primary key (rep_id)

create table actor ( act_id integer not null, rep_id integer not null, pai_id integer not null, act_nombre varchar(40) not null, act_fechanacimiento date, constraint PK_actor primary key (act_id)

);

alter table categoria add constraint fk_categoria_pelicula foreign key(pel_id) references pelicula(pel_id); alter table Actua add constraint fk_Actua_pelicula foreign key(pel_id) references pelicula(pel_id); alter table actua add constraint fk_actua_actor foreign key(act_id) references actor(act_id); alter table actor add constraint fk_actor_representante foreign key(rep_id) references representante(rep_id); alter table actor add constraint fk_actor_pais foreign key (pai_id) references pais(pai_id);

drop drop drop drop drop drop

table table table table table table INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO

Categoria; Pelicula; Actua; pais; representante; actor; CATEGORIA CATEGORIA CATEGORIA CATEGORIA CATEGORIA CATEGORIA PELICULA PELICULA PELICULA PELICULA PELICULA PAIS PAIS PAIS PAIS PAIS VALUES VALUES VALUES VALUES VALUES VALUES (1001,301,'CAT1',''); (1002,302,'CAT2',''); (1003,303,'CAT3',''); (1004,304,'CAT4',''); (1005,305,'CAT5',''); (1006,306,'CAT6','');

INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT

VALUES (301,'JUEGOS DEL HAMBRE',120,''); VALUES (302,'AMOR',60,''); VALUES (303,'EL VUELO',230,''); VALUES (304,'mayor6anios'70,''); VALUES (305,'RAPIDO Y FURIOSO',80,''); (10001,'Colombia'); (10002,'Argentina'); (10003,'USA'); (10004,'Canada'); (10005,'Inglaterra');

VALUES VALUES VALUES VALUES VALUES

INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT INSERT 1.

INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO INTO

REPRESENTANTE REPRESENTANTE REPRESENTANTE REPRESENTANTE REPRESENTANTE ACTOR ACTOR ACTOR ACTOR ACTOR ACTOR ACTOR ACTOR ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA ACTUA VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES VALUES

VALUES VALUES VALUES VALUES VALUES

(101,'CARLOS PEREZ','A@A','oficina 1'); (102,'JUAN DIAZ','D@D','OFICINA2'); (103,'JULIANA COLINA','S@S','OFICINA3'); (104,'SARA COLLAZOS','W@W','OFICINA4'); (105,'PEDRO SARRIA','G@Q','OFICINA5');

(1,103,10001,'JENNIFER LAWRENCE',''); (2,103,10002,'BEN AFFLECK',''); (3,101,10002,'Angelina Jolie',''); (4,102,10002,'Brad Pitt',''); (5,102,10003,'Julia Roberts',''); (6,104,10003,'Leonardo Dicaprio',''); (7,104,10004,'Jean Claude Van Damme',''); (8,103,10002,'Nicole Kidman',''); (11,301,1,234,320000); (12,301,2,234,320000); (13,301,3,234,320000); (14,301,1,234,320000); (15,302,2,234,800000); (16,302,1,234,920000); (17,302,3,234,320000); (18,303,1,234,420000); (19,303,4,234,560000); (20,304,7,234,410000); (21,305,5,234,230000); (22,305,6,234,560000);

select cat_nombre from categoria inner join actua on(categoria.pel_id=actua.pel_id) where act_id=1; 2. select count(act_nombre),pel_id from actor inner join actua on(actor.act_id=actua.act_id) group by (pel_id);

3. create view actores as( select count(actua.pel_id) as peliculas,actor.act_id from actor inner join actua on(actor.act_id=actua.act_id) group by (actor.act_id)); select peliculas,act_id from actores where peliculas>3; 4. create view ganancia as( select actor.act_id,salario,actor.rep_id from actor inner join actua on (actor.act_id=actua.act_id));

create view valor_ganancia as( select (salario*0.20) as ganancias,representante.rep_id from ganancia inner join representante on (ganancia.rep_id=representante.rep_id) ) select sum(ganancias)as total_ganado,representante.rep_id from representante inner join valor_ganancia on (representante.rep_id=valor_gana ncia.rep_id) group by (representante.rep_id); 5. select actua.pel_id from actua inner join pelicula on (pelicula.pel_id=actua.pel_id) group by (actua.pel_id) having sum(salario)>2000000; 6. select count(cat_nombre),actua.act_id from categoria inner join actua on(categoria.pel_id=actua.pel_id) where act_id=3 group by (actua.act_id); 7. create view mayor_cantidad as( select count(actua.act_id)as cantidad,pelicula.pel_id,pelicula.pel_nombre from pelicula inner join actua on(pelicula.pel_id=actua.pel_id) group by (pelicula.pel_id,pelicula.pel_nombre)); 8. select pelicula.pel_id,avg(salario) from actua inner join pelicula on (pelicula.pel_id=actua.pel_id) group by (pelicula.pel_id) order by (pelicula.pel_id);

Potrebbero piacerti anche