You are on page 1of 3

Universidad Nacional de Trujillo.

Base de Datos

LABORATORIO N 04
SQL SUBCONSULTAS
Los organizadores de un festival de teatro mantienen la informacin del mismo en una base dedatos
con el siguiente esquema:
INVITADO (NroInvit, Nombre, Categora, Origen)
Contiene informacin de las personas invitadas al festival. A cada persona se le asigna un nrode
invitado que lo identifica y se conoce su nombre, su categora (ej: prensa, crtica, etc.) y supas de
origen.
TEATRO (CodTeat, Nombre, Direccin, CantAsientos)
Contiene informacin de los teatros que participan del festival. De cada teatro se conoce lacantidad
de asientos disponibles, los cuales condicionan la cantidad de reservas que sepueden realizar para el
mismo.
OBRA (CodObra, NombreObra, Autor)
Contiene informacin de las obras exhibidas en el festival.
EXHIBICION (CodExhib, CodTeat,Fecha, CodObra)
Contiene informacin del calendario de obras a exhibirse durante el festival.
RESERVA (CodTeat, Fecha, NroAsiento, NroInvit)
Mediante sentencias SQl, dar solucin a los siguientes requerimientos
a) Obtener el nombre del teatro que tenga la mxima cantidad de asientos
b) Obtener el nombre de la obra que tuvo la fecha ms antigua de exhibicin
c) Obtener el nombre de los invitados que han realizado una nica reserva
d) Actualizar la cantidad de asientos en 100% de aquellos teatros que no tengan exhibicin
alguna.
e) Obtener el nombre de los invitados que han realizado reserva alguna.
f) Obtener el nombre del teatro donde se exhibido la obra El Principito.
g) Obtener el nombre del teatro donde se realiz la exhibicin ms reciente.
h) Obtener el cdigo del teatro y la cantidad de obras realizadas por teatro de aquellos teatros
que se hayan realizado ms de 1 obras.
INSERTINTOINVITADO(NroInvitado,Nombre,Categoria,Origen)
VALUES ('001','Julio','prensa','Francia')
INSERTINTOINVITADO(NroInvitado,Nombre,Categoria,Origen)
VALUES ('002','Pedro','critica','Brasil')
INSERTINTOINVITADO(NroInvitado,Nombre,Categoria,Origen)
VALUES ('003','Pablo','critica','Islandia')
INSERTINTOINVITADO(NroInvitado,Nombre,Categoria,Origen)
VALUES ('004','Juan','prensa','Irak')
INSERTINTOINVITADO(NroInvitado,Nombre,Categoria,Origen)
VALUES ('005','Luis','critica','USA')
SELECT*FROMINVITADO
INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('101','BRUSELAS','av Arica','200')
INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('102','AMERICANO','jr Peru','300')

Universidad Nacional de Trujillo. Base de Datos


INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('103','JAPONES','prol Union','400')
INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('104','NACIONAL','calle Baltodano','500')
INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('105','INDU','av Ugarte','200')
INSERTINTOTEATRO(CodTeatro,Nombre,Direccion,CantAsientos)
VALUES ('106','san juan','independencia','260')
SELECT*FROMTEATRO
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('201','Muchik','Juan Martinez')
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('202','Dragon Rojo','Lau Chau')
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('203','La Esperanza','Jose Sanchez')
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('204','Dos mas dos','Santos Llanos')
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('205','Mejor soy angel','Edwin Ferrer')
INSERTINTOOBRA(CodObra,NombreObra,Autor)
VALUES ('206','la sopa','jose lopez')
SELECT*FROMOBRA
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('301','101','25/11/2015','201')
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('302','102','02/12/2015','202')
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('303','103','28/12/2015','203')
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('304','104','04/11/2015','204')
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('305','105','27/10/2015','205')
INSERTINTOEXHIBICION(CodExhib,CodTeatro,Fecha,CodObra)
VALUES ('306','105','22/12/2015','206')
SELECT*FROMEXHIBICION
INSERTINTORESERVA(CodTeatro,Fecha,NroAsiento,NroInvitado)
VALUES ('101','25/11/2015','110','001')
INSERTINTORESERVA(CodTeatro,Fecha,NroAsiento,NroInvitado)
VALUES ('102','02/12/2015','111','002')
INSERTINTORESERVA(CodTeatro,Fecha,NroAsiento,NroInvitado)
VALUES ('103','28/12/2015','112','003')
INSERTINTORESERVA(CodTeatro,Fecha,NroAsiento,NroInvitado)
VALUES ('104','04/11/2015','113','004')
INSERTINTORESERVA(CodTeatro,Fecha,NroAsiento,NroInvitado)
VALUES ('105','27/10/2015','114','005')
SELECT*FROMRESERVA
SELECT*FROMINVITADO
SELECT*FROMTEATRO
SELECT*FROMEXHIBICION
SELECT*FROMOBRA

Universidad Nacional de Trujillo. Base de Datos


SELECTNombrefromTEATRO
whereCantAsientos=
(SELECTMAX(CantAsientos)fromTEATRO)
selectNombreObrafromOBRA
whereCodObra=
(selectCodObrafromEXHIBICION
whereFecha=
(selectMIN(Fecha)fromEXHIBICION))
selectNombrefromINVITADO
whereNroInvitadoin
(selectNroInvitadofromRESERVA
whereNroAsientoin
(selectNroAsientofromRESERVA
groupbyNroAsientohavingCOUNT(*)=1))
updateTEATRO
setCantAsientos=CantAsientos*2
whereCodTeatronotin
(selectCodTeatrofromEXHIBICION)
selectNombrefromINVITADO
whereNroInvitadoin
(selectNroInvitadofromRESERVA)
selectNombrefromTEATRO
whereCodTeatro=
(selectCodTeatrofromEXHIBICION
WHERECodObra=
(selectCodObraFROMOBRA
whereNombreObra='Dragon Rojo'))
SELECTNombrefromTEATRO
whereCodTeatro=
(selectCodTeatrofromEXHIBICION
whereFecha=
(selectMAX(Fecha)fromEXHIBICION))
selectCodTeatrofromTEATRO
whereCodTeatroin
(selectCodTeatrofromEXHIBICION
whereCodTeatroin
(selectCodTeatrofromEXHIBICIONgroupbyCodTeatrohavingCOUNT(*)>1))

You might also like