-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAProcedures.sql
76 lines (72 loc) · 1.5 KB
/
AProcedures.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
delimiter $$
CREATE PROCEDURE ATodosTestes(IN nif_atleta int)
begin
Select
T.*
From
TesteClinico as T,
Atleta as A
where
A.nif = T.nif
and A.nif = nif_atleta;
end $$
delimiter ;
delimiter $$
CREATE PROCEDURE ATestesEmClinica(IN n_clinica int, IN n_atleta INT)
begin
Select
T.*
From
TesteClinico as T,
Atleta as A
where
T.nif = A.nif
and A.nif = n_atleta
and T.cod_clinica = n_clinica;
end$$
delimiter ;
delimiter $$
CREATE PROCEDURE ATestesEntreDatas(IN d_start DATE, IN d_end DATE, IN n_atleta INT)
begin
Select *
From
TesteClinico as T,
Atleta as A
where
T.nif = A.nif
and A.nif = n_atleta
and T.data between d_start and d_end;
end $$
delimiter ;
delimiter $$
CREATE PROCEDURE ATestesPrecoCrescente(In nif_atleta int)
begin
Select
T.id_teste,
T.preco
From
Atleta as A,
TesteClinico as T
where
A.nif = T.nif
and A.nif = nif_atleta
order by T.preco;
end $$
delimiter ;
delimiter $$
CREATE PROCEDURE AClinicaEmQueMaisGasta(In nif_atleta int)
begin
Select
T.cod_clinica,
sum(T.preco) as Gasto
From
Atleta as A,
TesteClinico as T
where
A.nif = T.nif
and A.nif = nif_atleta
group by T.cod_clinica
order by sum(T.preco) DESC
limit 1;
end $$
delimiter ;