ci int not null primary key , nombre varchar (50)not null , sexo varchar(1) not null, telefono int , ciavala int ); alter table cliente add foreign key(ciavala) references cliente(ci) on update no action on delete no action
create table TipoCredito (
id int not null primary key, descripcion varchar(50) not null, )
create table prestamo(
nro varchar(3) not null primary key , fecha date not null, plazo int not null, monto float not null , ciCliente int not null , idTipo int not null, foreign key (cicliente) references cliente(ci) on update cascade on delete cascade, foreign key (idTipo)references TipoCredito(id) on update cascade on delete cascade )
create table cuotas(
nrop varchar(3) not null, nroCuota int not null, fecha date not null, monto float not null, foreign key (nrop) references prestamo(nro) on update cascade on delete cascade )
insert into cliente values(101,'joaquin chumacero yupanqui','m',3567587,null)
insert into cliente values(102,'patricia aguilera candia','f',7098899,101) insert into cliente values(103,'saturnino mamani rodriguez','m',null,101) insert into cliente values(104,'fabio martinez','m',6093333,103)
insert into TipoCredito values(1,'consumo')
insert into TipoCredito values(2,'educativo') insert into TipoCredito values(3,'negocio')
insert into prestamo values('p1','2011/05/15',3,1000,103,2)
insert into prestamo values('p2','2011/05/17',2,500,104,3) insert into prestamo values('p3','2011/05/17',2,700,102,3) insert into prestamo values('p4','2011/05/19',3,300,103,2) select * from prestamo insert into cuotas values('p1',1,'2011/06/15',333.33) insert into cuotas values('p1',2,'2011/07/15',333.33) insert into cuotas values('p1',3,'2011/08/15',333.33) insert into cuotas values('p2',1,'2011/06/17',255) insert into cuotas values('p2',2,'2011/06/17',255) insert into cuotas values('p3',1,'2011/06/17',350) insert into cuotas values('p3',2,'2011/07/17',350) insert into cuotas values('p4',1,'2011/06/19',100) insert into cuotas values('p4',2,'2011/07/19',100) insert into cuotas values('p4',3,'2011/08/19',100) /* MOSTRAR LAS CUOTAS DE LOS CREDITOS DE AQUELLOS QUE FUERON AVALADOS POR SATURNINO MAMANI RODRIGUEZ */ select * from cuotas where nrop in( select nro from prestamo where ciCliente in ( select ci from cliente where ciavala in (
select ci
from cliente
where nombre='saturnino mamani rodriguez'
) ) )
/* MOSTRAR EL MONTO TOTAL DE LOS CREDITOS DE NEGOCIOS
from cliente, prestamo,TipoCredito,cuotas where ci=ciCliente and nro=nrop and id=idTipo and sexo='m' and descripcion='negocio' group by nrop,ci,nombre,nro
/* MOSTRAR TODOS LOS CLIENTES QUE HAN SACADO MAYOR O IGUAL A 1
PRESTAMOS DE TIPO EDUCATIVO */ select ci,nombre, COUNT(nrop) from cliente, prestamo,TipoCredito,cuotas where ci=ciCliente and nro=nrop and id=idTipo and descripcion='educativo' group by ci,nombre,nrop having COUNT(nrop)>=1
/* MOSTRAR EL MONTO MAXIMO SACADO POR CADA CLIENTE VARON */
select ci,nombre, SUM(cuotas.monto)as monto_total from cliente, prestamo,cuotas where ci=ciCliente and nro=nrop and sexo='m' group by ci,nombre