-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPunto_07.sql
More file actions
44 lines (33 loc) · 972 Bytes
/
Copy pathPunto_07.sql
File metadata and controls
44 lines (33 loc) · 972 Bytes
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
/*
Nota de un curso por estudiante por periodo
*/
CREATE OR ALTER FUNCTION F_AverageScoreStudentByPeriod( @Ln_id_period INT, @Ln_id_student INT)
RETURNS DECIMAL
AS
BEGIN
DECLARE @Ln_promedio DECIMAL;
Select @Ln_promedio = sum(score)/count(1)-- AVG(PCS.score)
From [periods] P
Right Join periods_courses PC
Right Join periods_courses_suscriptions PCS
On PCS.id_periods_courses = PC.id
And PCS.student_id = @Ln_id_student
On PC.id_periods = P.id
Where P.id = @Ln_id_period;
RETURN ISNULL(@Ln_promedio,0);
END;
SELECT [dbo].F_AverageScoreStudentByPeriod(1,28);
/*
Promedio de notas por alumno
*/
CREATE OR ALTER FUNCTION F_AverageScoreStudent( @Ln_id_student INT)
RETURNS DECIMAL
AS
BEGIN
DECLARE @Ln_promedio DECIMAL;
Select @Ln_promedio = sum(score)/count(1) -- @Ln_DECIMAL = AVG(score)
From periods_courses_suscriptions
Where student_id = @Ln_id_student;
RETURN ISNULL(@Ln_promedio,0);
END;
SELECT [dbo].F_AverageScoreStudent(6);