lunes, 12 de septiembre de 2011

33 consultas a Sis.Contr.Seg.Proy.Gob.El Alto

SELECT [campos|*] FROM [table] WHERE [condición]
1.Listar todos los funcionarios.
select *
from FUNCIONARIO

2. Listar las unidades que tengan el texto "EDUCACION" en su descripción.
select *
from unidad
where DESCRIPCION LIKE '%EDUCACION%'

3. Listar el código del funcionario que tiene como nombre: "LUISA REYES".
select *
from FUNCIONARIO
where nombre='Luisa Reyes'

4. Listar todos los distritos.
select *
from DISTRITO

5. Listar los proyectos que se iniciaron en fecha "03-30-2010".
select *
from PROYECTO
where fechainicio=2010-03-30

6. Listar los distritos que tengan el texto "CALIDAD DE VIDA MEDIA".
select *
from distrito
where descripcion='CALIDAD DE VIDA MEDIA'

7. Listar los ítems de funcionarios cuyos telefonos se inicie con “732”.
select funcionario.ITEM
from FUNCIONARIO,TELEFONOF
WHERE FUNCIONARIO.Item=TELEFONOF.Item and telefonof.NROTELEFONO LIKE '732%'

8. Listar los proyectos cuyo código termine con “1?”.
select *
from proyecto
where codp LIKE '%1'

 9. Listar los proyectos cuyo carnet empiece con “0000”.
select *
from proyecto
where codp LIKE '0000%'

 10. Listar todas las unidades.
select *
from unidad

11. Determinar la cantidad de pasos que siguió el proyecto  000006
select codDoc
from SEGUIMIENTO
where CODPROY='000006'

12. Determinar la cantidad de documentos con extension “aplicable”
select count(extencion)
from documento
where extencion='aplicable'

13. Determinar la cantidad de documentos tipo “Minuta Descriptiva” y extension “aplicable”
select count(extencion)
from documento
where extencion='aplicable' and descripcion='minuta descriptiva'

14. Listar todos los proyectos que se iniciaron a partir del ‘20/12/1990’
select *
from PROYECTO
where fechainicio>1990-12-20

15. Listar todos los documentos correspondientes al proyecto ‘000009
select a.nombre
from documento a, seguimiento b
where a.codD=b.codDoc and codProy='000009'

16. Cuantos y cuales son pasos en los que intervino el funcionario 146?.
select nombre
from funcionario
where item=104

17. Quién es el funcionario 104?
select nombre
from funcionario
where item=104

18. Cuántos registros tiene la tabla unidad?
select count(nombreU)
from unidad

19. El remanente del proyecto ‘000005’ esta correcto?
select remanente
from presupuesto
where codproy='000005'

20. Cuánto se presupuesto en todos los proyectos?
select sum(costoini)
from presupuesto

21. Cuántos proyectos se llevan a cabo en el distrito 0006? (4 filas)
select count(*)
from dist_proy
where nroDist=6

22. Cuántos distritos son del tipo ‘CALIDAD DE VIDA BAJA’?
select *
from distrito
where descripcion='CALIDAD DE VIDA BAJA'

23. Mostrar los proyectos que se adjudico la empresa ‘Coca Cola’
select B.CODPROY
from EMPRESA A,ADJUDICACION B
WHERE B.NIT=A.NIT AND A.NOMBRE='COCA-COLA'

24. Determinar el monto entre todos los proyectos adjudicados por la empresa ‘000008’?
select sum(costofin)
from PRESUPUESTO
WHERE CODPROY='000008'

25. Cuántos son los proyectos presupuestados con mas de 15.000Bs?
select nombre
from PROYECTO
WHERE codp in (select codproy
from PRESUPUESTO
WHERE costoIni>15000)

26. Cuántos son los proyectos financiados por el Banco Mundial u ONG?
select nombre
from PROYECTO
WHERE codp in (select codproy
from PRESUPUESTO
WHERE nrocp in (select nrocp
from TIPO_FINANCIAMIENTO
WHERE nombre='Banco Mundial u ONG’))

27. Mostrar los proyectos financiados por la empresa ‘SOBOCE’?
select nombre
from PROYECTO
WHERE codp in (select codproy
from PRESUPUESTO
WHERE nrocp in (select nrocp
from TIPO_FINANCIAMIENTO
WHERE nombre='SOBOCE’))

28. Determinar los proyectos con monto superior a 20.000 de costo inicial?
select nombre
from PROYECTO
WHERE codp in (select codproy
from PRESUPUESTO
WHERE (costoIni-costoIni)>20000)

29. Determinar la cantidad de funcionarios de la unidad ’cobranzas’?
select count(nombreU)
from FUNCIONARIO
WHERE nombreU=’cobranzas’)

30. Mostrar la unidad en la que se encuentra el funcionario ‘MENDEZ PRIETO VICTOR’?
select nombreU
from FUNCIONARIO
WHERE nombre=’ MENDEZ PRIETO VICTOR

31. Determinar el numero de usuarios cuyo idUsuario empieza con el carácter ‘M’?
select count(Item)
from USUARIO
WHERE idUsuario =’M%

32. Determinar la cantidad de teléfonos del funcionario104?
select count(ITEM)
from TELEFONOF
WHERE item=104
33. Mostrar los números de teléfono de la empresa 524413?
select nrotelefono
from TELEFONOE
WHERE nit=524413

Ingreso de datos en la base de datos

INSERT INTO PROVEEDOR VALUES ('0001','luis','loza mamani','Av.Sucre','La Paz','Bolivia',2831840,1,1);
INSERT INTO PROVEEDOR VALUES ('0002','Marco','Llanos Condori','Miraflores','La Paz','Bolivia',2486975,2,2);
INSERT INTO PROVEEDOR VALUES ('0003','Ana','Terrazas Miranda','C.RosGutierrez','La Paz','Bolivia',2486975,3,3);
INSERT INTO PROVEEDOR VALUES ('0004','Miriam','Perez Alarcon','Av. Villazon','La Paz','Bolivia',2824569,4,4);
INSERT INTO PROVEEDOR VALUES ('0005','Clara','Quiroz Ruiz','El Prado','La Paz','Bolivia',2526478,5,5);
INSERT INTO CLIENTE VALUES ('Carlos','Murillo Mejillones','245154 lp',2831414,'Miraflores','0001');
INSERT INTO CLIENTE VALUES ('Juan',' Verastegui','524413 lp',79513443,'Av.Principal','0002');
INSERT INTO CLIENTE VALUES ('Mercedes','SossaCarlos','745144 lp',2254698,'Av. Villazon','0003');
INSERT INTO CLIENTE VALUES ('Pablo','Milanes','325235 lp',7789878,'Av. Villazon','0004');
INSERT INTO CLIENTE VALUES ('Luisa','Reyes','524413 lp',7736547,'Av.Principal','0005');
INSERT INTO USUARIO VALUES ('0001','524413 lp','Carlos','Murillo Mejillones','contador','contabilidad',7736547,'Av.Principal');
INSERT INTO USUARIO VALUES ('0002','544345 lp','jose','Mamani cantutani','almacenero','contabilidad',7734554,'Av.Leones');
INSERT INTO USUARIO VALUES ('0003','598904 lp','pablo','Peralta Murillo','contador','portero',7237365,'Av.Palca');
INSERT INTO USUARIO VALUES ('0004','234903 lp','maria','Mendoza meza','contador','auxiliar',6349477,'Av.segunda');
INSERT INTO USUARIO VALUES ('0005','987453 lp','josue','Carvajal Melchor','contador','vendedor',4958773,'Av.quintanilla');
INSERT INTO PEDIDO VALUES ('0001','1/1/2011',20,'Bolivia','La Paz','BS');
INSERT INTO PEDIDO VALUES ('0002','4/1/2011',10,'Bolivia','La Paz','BS');
INSERT INTO PEDIDO VALUES ('0003','5/1/2011',20,'Bolivia','La Paz','BS');
INSERT INTO PEDIDO VALUES ('0004','6/1/2011',10,'Bolivia','La Paz','BS');
INSERT INTO PEDIDO VALUES ('0005','7/1/2011',30,'Bolivia','La Paz','BS');
---
INSERT INTO RECIBO VALUES ('0001','7/1/2011',300,'venta de producto A');
INSERT INTO RECIBO VALUES ('0002','7/2/2011',500,'venta de producto B');
INSERT INTO RECIBO VALUES ('0003','2/3/2011',400,'venta de producto C');
INSERT INTO RECIBO VALUES ('0004','4/5/2011',300,'venta de producto D');
INSERT INTO RECIBO VALUES ('0005','6/6/2011',200,'venta de producto A');
INSERT INTO COMPRA VALUES ('0005','0001','6/6/2011','A','0001');
INSERT INTO COMPRA VALUES ('0004','0001','1/1/2011','B','0002');
INSERT INTO COMPRA VALUES ('0003','0001','2/3/2011','C','0003');
INSERT INTO COMPRA VALUES ('0002','0001','3/2/2011','D','0004');
INSERT INTO COMPRA VALUES ('0001','0001','4/5/2011','E','0005');
INSERT INTO VENTA VALUES ('1','6/6/2011','0001',100,'A','venta actual');
INSERT INTO VENTA VALUES ('2','2/2/2011','0002',100,'A','venta anterior');
INSERT INTO VENTA VALUES ('3','3/3/2011','0003',100,'B','venta general');
INSERT INTO VENTA VALUES ('4','4/4/2011','0004',100,'B','venta posterior');
INSERT INTO VENTA VALUES ('5','5/6/2011','0005',100,'A','venta actual');
INSERT INTO ALMACEN VALUES ('general','0001','av. miraflores',72564852,'0001');
INSERT INTO ALMACEN VALUES ('costanera','0002','av. santa cruz',34567252,'0002');
INSERT INTO ALMACEN VALUES ('junin','0003','av. copacabana',79842564,'0003');
INSERT INTO ALMACEN VALUES ('el alto','0004','av. tiwanaco',72283752,'0004');
INSERT INTO ALMACEN VALUES ('central','0005','av. el prado',23454852,'0005');
INSERT INTO PRODUCTO VALUES ('0001','zapatos',50,70,'color blanco deportivo','0001',1,1,'manaco','M','L','blanco');
INSERT INTO PRODUCTO VALUES ('0002','chompa',40,70,'deportivo','0002',2,2,'alpaca','M','L','cafe');
INSERT INTO PRODUCTO VALUES ('0003','pantalon',60,80,'color azul','0003',3,3,'lee','H','M','azul');
INSERT INTO PRODUCTO VALUES ('0004','toalla',30,80,'color blanco','0004',4,4,'nike','H','M','blanco');
INSERT INTO PRODUCTO VALUES ('0005','camisa',20,40,'color blanco','0005',5,5,'patito','M','M','blanco');
---
INSERT INTO CUENTA_POR VALUES ('0001',1,'6/6/2011',10,300,290,'A',1,'0001');
INSERT INTO CUENTA_POR VALUES ('0002',2,'2/1/2011',5,400,395,'A',2,'0002');
INSERT INTO CUENTA_POR VALUES ('0003',3,'3/2/2011',10,500,490,'A',3,'0003');
INSERT INTO CUENTA_POR VALUES ('0004',4,'4/4/2011',20,600,580,'A',4,'0004');
INSERT INTO CUENTA_POR VALUES ('0005',5,'5/3/2011',10,300,290,'A',5,'0005');
INSERT INTO DETALLE_COMPRA VALUES (1,'0005',5,'B','A','A');
INSERT INTO DETALLE_COMPRA VALUES (2,'0004',6,'A','A','A');
INSERT INTO DETALLE_COMPRA VALUES (3,'0003',2,'C','A','A');
INSERT INTO DETALLE_COMPRA VALUES (4,'0002',8,'D','A','A');
INSERT INTO DETALLE_COMPRA VALUES (5,'0001',4,'B','A','A');
INSERT INTO DETALLE_VENTA VALUES (5,'0001',4,100,10,90);
INSERT INTO DETALLE_VENTA VALUES (4,'0002',5,300,10,270);
INSERT INTO DETALLE_VENTA VALUES (3,'0003',6,200,10,180);
INSERT INTO DETALLE_VENTA VALUES (2,'0004',7,100,10,90);
INSERT INTO DETALLE_VENTA VALUES (1,'0005',8,100,10,90);
INSERT INTO DETALLE_PEDIDO VALUES (100,8,'0005',1);
INSERT INTO DETALLE_PEDIDO VALUES (100,10,'0004',2);
INSERT INTO DETALLE_PEDIDO VALUES (100,18,'0003',3);
INSERT INTO DETALLE_PEDIDO VALUES (100,81,'0002',4);
INSERT INTO DETALLE_PEDIDO VALUES (100,85,'0001',5);
INSERT INTO STOCK VALUES ('0001',2,50,10,100);
INSERT INTO STOCK VALUES ('0002',3,40,1,40);
INSERT INTO STOCK VALUES ('0003',4,70,3,50);
INSERT INTO STOCK VALUES ('0004',5,90,8,1);
INSERT INTO STOCK VALUES ('0005',7,20,20,80);
INSERT INTO USU_AL VALUES ('0005','0001');
INSERT INTO USU_AL VALUES ('0004','0002');
INSERT INTO USU_AL VALUES ('0003','0003');
INSERT INTO USU_AL VALUES ('0002','0004');
INSERT INTO USU_AL VALUES ('0001','0005');

Creacion de la base de datos

CREATE DATABASE EDDY
USE EDDY

CREATE TABLE PROVEEDOR(
cod_proveedor varchar(4)not null,
nombre varchar(20)not null,
apellidos varchar(30)not null,
direccion varchar(15)not null,
dpto varchar(15)not null,
pais varchar(15)not null,
telefono int not null,
nro_compra int not null,
nit int not null,  
primary key(cod_proveedor));

CREATE TABLE CLIENTE(
nombre varchar(20)not null,
apellidos varchar(30)not null,
ci varchar(15)not null,
telefono int not null,
direccion varchar(15)not null,
cod_cliente varchar(4)not null,
primary key(cod_cliente));

CREATE TABLE USUARIO(
cod_usuario varchar(4)not null,
ci varchar(15)not null,
nombre varchar(20)not null,
apellidos varchar(30)not null,
cargo varchar(40)not null,
dpto varchar(15)not null,
telefono int not null,
direccion varchar(15)not null,
primary key(cod_usuario));

CREATE TABLE PEDIDO(
nro_pedido int not null,
fecha datetime not null,
cantidad int not null,
pais varchar(15)not null,
ciudad varchar(15)not null,
moneda varchar(2)not null,
primary key(nro_pedido));

CREATE TABLE RECIBO(
cod_recibo varchar(4)not null,
fecha datetime not null,
monto float not null,
descripcion varchar(50)not null,
primary key(cod_recibo));

CREATE TABLE ALMACEN(
nombre varchar(20)not null,
cod_almacen varchar(4)not null,
direccion varchar(15)not null,
telefono int not null,
cod_usuario varchar(4)not null,
primary key(cod_almacen),
foreign key(cod_usuario)references USUARIO);

CREATE TABLE PRODUCTO(
cod_producto varchar(4)not null,
nombre varchar(20)not null,
precio_costo float not null,
precio_venta float not null,
descripcion varchar(50)not null,
cod_almacen varchar(4)not null,
nro_venta int not null,
nro_compra int not null,
marca varchar(15)not null,
genero varchar(1)not null,
talla varchar(1)not null,
color varchar(10)not null,
primary key(cod_producto),
foreign key(cod_almacen)references ALMACEN);

CREATE TABLE VENTA(
nro_venta int not null,
fecha datetime not null,
cod_cliente varchar(4)not null,
total_venta float not null,
tipo_pago varchar(1)not null,
descripcion varchar(50)not null,
primary key(nro_venta),
foreign key(cod_cliente)references CLIENTE);

CREATE TABLE COMPRA(
nro_compra int not null,
cod_proveedor varchar(4)not null,
fecha_compra datetime not null,
tipo varchar(1)not null,
nro_pedido int not null,
primary key(nro_compra),
foreign key(cod_proveedor)references PROVEEDOR,
foreign key(nro_pedido)references PEDIDO);

CREATE TABLE CUENTA_POR(
cod_proveedor varchar(4)not null,
nro_compra int not null,
fecha datetime not null,
debe float not null,
saldo float not null,
pagado float not null,
tipo_cuenta varchar(1)not null,
nro_venta int not null,
cod_recibo varchar(4)not null,
foreign key(cod_proveedor)references PROVEEDOR,
foreign key(nro_compra)references COMPRA,
foreign key(nro_venta)references VENTA,
foreign key(cod_recibo)references RECIBO);

CREATE TABLE DETALLE_COMPRA(
nro_compra int not null,
cod_producto varchar(4)not null,
cantidad int not null,
precio_listado varchar(1)not null,
descuento varchar(1)not null,
total_compra varchar(1)not null,
foreign key(nro_compra)references COMPRA,
foreign key(cod_producto)references PRODUCTO);

CREATE TABLE DETALLE_VENTA(
nro_venta int not null,
cod_producto varchar(4)not null,
cantidad int not null,
precio_venta float not null,
descuento float not null,
total_venta float not null,
foreign key(nro_venta)references VENTA,
foreign key(cod_producto)references PRODUCTO);

CREATE TABLE DETALLE_PEDIDO(
costo float not null,
cantidad int not null,
cod_producto varchar(4)not null,
nro_pedido int not null,
foreign key(cod_producto)references PRODUCTO,
foreign key(nro_pedido)references PEDIDO);

CREATE TABLE STOCK(
cod_producto varchar(4)not null,
cant_vendia int not null,
cant_pedida int not null,
saldo float not null,
cantidad int not null,
foreign key(cod_producto)references PRODUCTO);

CREATE TABLE USU_AL(
cod_usuario varchar(4)not null,
cod_almacen varchar(4)not null,
foreign key(cod_usuario)references USUARIO,
foreign key(cod_almacen)references ALMACEN