forked from mestanza/MySQL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstored_procedures.sql
77 lines (61 loc) · 3.57 KB
/
stored_procedures.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
create database sams;
use sams;
show tables;
#------------------------------------------------------------------------------------------------
delimiter #
show tables #
create procedure proc_uno()
begin
select count(idGerente) as total_en_gerentes from gerente;
select club.nombre,socio.nombre, estado.nombre from club,socioclub,socio,estado where club.idClub=socioclub.idClub and socio.idSocio=socioclub.idSocio and club.idEdo=estado.idEdo and estado.nombre like 'M%xico';
select club.nombre from club,servicioclub,servicio where club.idClub=servicioclub.idClub and servicioclub.idServicio=servicio.idServicio and servicio.nombre='APPLE SHOP';
end #
create procedure proc_unopuntouno(in nombreSer varchar (30))
begin
select count(idGerente) as total_en_gerentes from gerente;
select club.nombre,socio.nombre, estado.nombre from club,socioclub,socio,estado where club.idClub=socioclub.idClub and socio.idSocio=socioclub.idSocio and club.idEdo=estado.idEdo and estado.nombre like 'M%xico';
select club.nombre from club,servicioclub,servicio where club.idClub=servicioclub.idClub and servicioclub.idServicio=servicio.idServicio and servicio.nombre like nombreSer;
end #
delimiter ;
select nombre from servicio;
call proc_uno();
call proc_unopuntouno('Farmacia');
select gerente.nombre from gerente,club where gerente.idClub=club.idClub and club.nombre='TOLUCA';
desc proveedor;
#----------------------------------------------------------------------------------------------
delimiter #
create procedure proc_dos(in nombrePr varchar(45))
begin
select gerente.nombre from gerente,club where gerente.idClub=club.idClub and club.nombre='TOLUCA';
select servicio.nombre from servicio,club,servicioclub where club.idClub=servicioclub.idClub and servicioclub.idServicio=servicio.idServicio and club.nombre='TOLUCA';
select proveedor.nombre from club inner join proveedorsams on club.idClub=proveedorsams.idClub inner join proveedor on proveedorsams.idProveedor=proveedor.idProveedor where club.nombre like nombrePr;
end #
delimiter ;
call proc_dos('TOLUCA');
select * from proveedor;
#---------------------------------------------------------------------------------------------
delimiter $
create procedure proc_tres()
begin
select nombre from socio where nombre like '%Gonzalez%';
select count(idSocio) as numero_socios from socio;
select producto.nombre, producto.precioUnitario from producto inner join proveedor on producto.idProveedor= proveedor.idProveedor and proveedor.nombre='Sabritas';
select club.nombre,gerente.nombre,proveedor.nombre from proveedor,gerente,proveedorsams,estado,club where proveedor.idProveedor=proveedorsams.idProveedor and proveedorsams.idClub = club.idClub and club.idClub = gerente.idClub and club.idEdo=estado.idEdo and estado.nombre='Chiapas';
end $
delimiter ;
call proc_tres();
#-------------------------------------------------------------------------------------------------------
delimiter 7
create procedure proc_cuatro()
begin
select club.nombre, count(socio.idSocio) as numero_socios from club inner join socioclub on club.idClub = socioclub.idClub inner join socio on socioclub.idSocio = socio.idSocio group by club.nombre;
end 7
#-------------------------------------------------------------------------------------------------
delimiter 7
create procedure proc_cuatro_mejorado()
begin
select club.nombre, count(socio.idSocio) as numero_socios from club inner join socioclub on club.idClub = socioclub.idClub inner join socio on socioclub.idSocio = socio.idSocio group by club.nombre having count(socio.idSocio)=2;
end 7
delimiter ;
call proc_cuatro();
call proc_cuatro_mejorado();