-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLMS_views.sql
51 lines (44 loc) · 1.39 KB
/
LMS_views.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
-- Creating view to get information about students, course they are enrolled in and the grades.
CREATE VIEW student_course_grades AS
SELECT
s.first_name,
s.last_name,
s.email,
c.title AS course_name,
g.grade AS student_grade
FROM students s
LEFT JOIN grades g
USING (student_id)
LEFT JOIN enrollments
USING (student_id)
LEFT JOIN courses c
USING(course_id);
-- ----------------------------------------------------------------------------------------------------
-- Creating view to get instructors and their course names
CREATE VIEW instructors_courses AS
SELECT
i.first_name,
i.last_name,
c.title AS course_title,
c.course_description,
c.duration_in_minutes AS course_duration_minutes
FROM instructors i
LEFT JOIN courses c
ON i.instructor_id = c.instructor_id;
-- ----------------------------------------------------------------------------------------------------
-- instructor_course_feedback view for instructors to check rating and comments on course.
CREATE OR REPLACE VIEW instructor_course_feedback
AS
SELECT
i.instructor_id,
i.first_name,
i.last_name,
c.title AS course_name,
f.comment,
f.rating AS course_rating
FROM instructors i
LEFT JOIN courses c
USING (instructor_id)
LEFT JOIN feedback f
ON c.course_id = f.course_id;
-- ----------------------------------------------------------------------------------------------------