Está en la página 1de 5

Gua lab 09 Alumno Medina Pineda Jordan Turno Noche Aula 142-C

create database COMERCIAL; USE COMERCIAL; create table Clientes( codcli char(3) primary key, nomcli varchar(40), apecli varchar(40), dircli varchar(40), distcli varchar(40), ruccli char(11), telcli varchar(15), fncli date, sexocli char(1) ); create table Productos( codpro char(3) primary key, nompro varchar(30), despro varchar(30), marpro varchar(30), prepro double, stock int, codcat char(3)

); create table Facturas( nrofactura char(6) primary key, codcli char(3), fecfac date, stfac double, igvfac double, mpfac double, codven char(2) ); create table detfac( nrofactura char(6), codpro char(3), cant int, total double ); create table vendedores( codven char(2) primary key, apeven varchar(30), nomven varchar(30) ); create table categoria( codcat char(3) primary key, nomcat varchar(30) ); alter table Facturas

add foreign key (codcli) references clientes(codcli); alter table detfac add foreign key (codpro) references Productos (codpro); alter table Productos add foreign key (codcat) references Categoria(codcat); alter table Facturas add foreign key(codven) references Vendedores(codven); insert into clientes values('001','Carranza Ruiz','Rafael','Av.Venezuela','brea','10141512123','4252623','1978-10-02','M'); insert into clientes(codcli,apecli,nomcli,dircli,distcli,telcli,fncli,sexocli) values('002','Oliva Mendez','Nancy','Jr.Junin 345','Pueblo libre','4645223','1973-05-14','F'); insert into clientes(codcli) values('003'); insert into clientes(codcli) values('004'); insert into clientes(codcli) values('005'); insert into categoria values('001','abarrotes'); insert into categoria values('002','panaderia'); insert into categoria values('003','lacteos'); insert into categoria values('004','limpieza'); insert into categoria values('005','aseo'); insert into Productos values('001','aceite','botella de 1 litro','primor',4.99,100,'001'); insert into Productos values('002','jabon','tocador','palmolive',2.5,50,'005'); insert into Productos (codpro)values('003');

insert into vendedores values('01','Garcia','Karen'); insert into vendedores values('02','Caceres','Carlos'); insert into Facturas values('000001','002','2007-09-14',10.50,1.99,12.49,'01'); insert into Facturas values('000002','001','2007-10-15',12.58,2.39,14.97,'02'); insert into detfac values('000001','002',3,7.50); insert into detfac values('000001','001',1,4.99); insert into detfac values('000002','001',2,9.98); y A

select * from comercial.clientes where dircli like('Av%'); y B

select * from comercial.productos order by prepro desc; y C

select * from comercial.clientes where fncli<='1986-01-01'; y D

select * from comercial.clientes where month(fncli)>=8 and month(fncli)<=12; y E

select * from comercial.clientes where day(fncli)=13 and dayofweek(fncli)=3; y F

select * from comercial.clientes where nomcli like('%r') or nomcli like('%n'); y G

select * from comercial.productos where despro like('A%') or despro like('__E%'); y H

select * from comercial.facturas where codcli='003' or codcli='006'; y I

select count(*) from comercial.clientes where ruccli is null;

select * from facturas,clientes where day(facturas.fecfac)=day(clientes.fncli) and month(facturas.fecfac)=month(clientes.fncli) and clientes.codcli=facturas.codcli; y K

select sum(detfac.cant) as cant,facturas.codcli from detfac,facturas where facturas.nrofactura=detfac.nrofactura group by detfac.nrofactura order by cant desc; y L

select count(*) as cantidad from facturas group by facturas.codcli order by cantidad desc;