-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSQL ejercio 6.sql
More file actions
92 lines (74 loc) · 2.73 KB
/
Copy pathSQL ejercio 6.sql
File metadata and controls
92 lines (74 loc) · 2.73 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
create database ejercicio6;
use ejercicio6;
Create table Fabricante(
codigo int auto_increment not null,
nombre varchar(50),
primary key (codigo)
);
create table Articulo(
codigo int auto_increment not null,
nombre varchar(50),
precio int,
fabricante int not null,
primary key(codigo),
constraint c1 foreign key(fabricante) references Fabricante(codigo)
);
DELIMITER $
CREATE procedure `InsertarFabricante`( nom varchar(50))
begin
insert into Fabricante(nombre) values (nom);
END$
DELIMITER $
create procedure `InsertarArticulo`(nom varchar(50), pre int,fabri int)
begin
insert into Articulo(nombre,precio,fabricante) values (nom,pre,fabri);
end$
DELIMITER $
create procedure `uno`()
begin
select AVG(Articulo.precio)as promedio from Articulo where Articulo.fabricante = 2;
end$
DELIMITER $
create procedure `dosA`()
begin
select nombre,precio from Articulo where Articulo.precio >= 180000 order by Articulo.precio Desc ;
end$
DELIMITER $
create procedure `dosB`()
begin
select nombre,precio from Articulo where Articulo.precio >= 180000 order by Articulo.nombre ASC;
end$
DELIMITER $
create procedure `tres`()
begin
select Fabricante.nombre, AVG(Articulo.precio) as PromedioArticulos from Articulo,Fabricante where Fabricante.codigo = Articulo.fabricante group by Fabricante.codigo ;
end$
DELIMITER $
create procedure `quinto`()
begin
update Articulo set precio = precio-10000 where precio >= 120000000; # no permite ejecutarlo desde workbench, Error, en la bd si lo permite
end$
DELIMITER $
create procedure `show5`()
begin
select codigo,nombre,precio from Articulo where precio >= 120000000;
end$
call ejercicio6.InsertarFabricante('HP');
call ejercicio6.InsertarArticulo('Pavilon750',750000,1);
call ejercicio6.uno();
call ejercicio6.dosA();
call ejercicio6.dosB();
call ejercicio6.tres();
call ejercicio6.quinto();
#select AVG(Articulo.precio)as promedio from Articulo,Fabricante where Articulo.fabricante= Fabricante.codigo and Fabricante.codigo = 2 ;
#uno
select AVG(Articulo.precio)as promedio from Articulo where Articulo.fabricante = 2;
#dos
select nombre,precio from Articulo where Articulo.precio >= 180000 order by Articulo.precio Desc ;
select nombre,precio from Articulo where Articulo.precio >= 180000 order by Articulo.nombre ASC;
#tres
select Fabricante.nombre, AVG(Articulo.precio) as PromedioArticulos from Articulo,Fabricante where Fabricante.codigo = Articulo.fabricante group by Fabricante.codigo ;
#cinco
update Articulo set precio = precio-10000 where precio >= 120000000; # no permite ejecutarlo desde workbench, Error, en la bd si lo permite
#no he podido
select Fabricante.nombre,Articulo.nombre, Max(Articulo.precio) as Precio from Articulo,Fabricante where Articulo.codigo in (select Articulo.codigo,Max(Articulo.precio) from Articulo ) ;