This repository has been archived by the owner on May 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.sql
143 lines (125 loc) · 5.12 KB
/
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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
CREATE VIEW webinar_financial_report AS
SELECT Webinar.id, CAST(SUM(Webinar.price) / 100.0 AS DECIMAL(10, 2)) AS income
FROM Webinar
INNER JOIN StudentWebinar on Webinar.id = StudentWebinar.webinar_id
GROUP BY Webinar.id;
GO
CREATE VIEW course_financial_report AS
SELECT Course.id,
CAST((dbo.course_full_income(Course.id) + dbo.course_advance_income(Course.id)) /
100.0 AS DECIMAL(10, 2)) AS income
FROM Course;
GO
CREATE VIEW studies_financial_report AS
SELECT Studies.id,
CAST(((dbo.studies_registration_income(Studies.id) + SUM(dbo.semester_income(Semester.id))) /
100.0) AS DECIMAL(10, 2)) AS income
FROM Studies
INNER JOIN Semester ON Studies.id = Semester.studies_id
GROUP BY Studies.id;
GO
CREATE VIEW students_who_purchased_meeting AS
SELECT Student.id, Student.first_name, Student.last_name, COUNT(*) AS purchased_meetings
FROM StudentMeeting
INNER JOIN Student ON StudentMeeting.student_id = Student.id
GROUP BY Student.id, Student.first_name, Student.last_name;
GO
CREATE VIEW debtor_list AS
SELECT DISTINCT TOP 100 PERCENT Student.id, Student.first_name, Student.last_name
FROM Student
INNER JOIN StudentCourse ON Student.id = StudentCourse.student_id AND StudentCourse.full_payment_date IS NULL
ORDER BY Student.id;
GO
CREATE VIEW future_studies_students AS
SELECT TOP 100 PERCENT Studies.id AS studies, Students.id, Students.first_name, Students.last_name
FROM Studies
CROSS APPLY dbo.students_enrolled_on_studies(Studies.id) AS students
WHERE dbo.studies_start_date(Studies.id) > CURRENT_TIMESTAMP
ORDER BY Studies.id, Students.id;
GO
CREATE VIEW future_courses_students AS
SELECT TOP 100 PERCENT Course.id AS course, Students.id, Students.first_name, Students.last_name
FROM Course
CROSS APPLY dbo.students_enrolled_on_course(Course.id) AS Students
WHERE dbo.course_start_date(Course.id) > CURRENT_TIMESTAMP
ORDER BY Course.id, Students.id;
GO
CREATE VIEW future_webinars_students AS
SELECT TOP 100 PERCENT Webinar.id AS webinar, Students.id, Students.first_name, Students.last_name
FROM Webinar
CROSS APPLY dbo.students_enrolled_on_webinar(Webinar.id) AS Students
WHERE Webinar.datetime > CURRENT_TIMESTAMP
ORDER BY Webinar.id, Students.id;
GO
CREATE VIEW future_meetings_students AS
SELECT TOP 100 PERCENT Meeting.id as meeting, Meeting.type, Students.id, Students.first_name, Students.last_name
FROM Meeting
CROSS APPLY (SELECT Student.id, Student.first_name, Student.last_name
FROM Student
INNER JOIN StudentMeeting ON Student.id = StudentMeeting.student_id
WHERE StudentMeeting.meeting_id = Meeting.id) AS students
WHERE Meeting.datetime > CURRENT_TIMESTAMP
ORDER BY Meeting.id, Students.id;
GO
CREATE VIEW attendance_on_meetings AS
SELECT TOP 100 PERCENT Meeting.id,
(SELECT COUNT(*) FROM dbo.students_enrolled_on_meeting(Meeting.id)) AS enrolled_students,
(SELECT COUNT(*) FROM dbo.students_present_on_meeting(Meeting.id)) AS present_students
FROM Meeting
WHERE Meeting.datetime < CURRENT_TIMESTAMP
ORDER BY Meeting.id;
GO
CREATE VIEW student_bilocation_list AS
SELECT TOP 100 PERCENT id, first_name, last_name
FROM Student
WHERE dbo.student_overlapping_meetings(id) = 1
ORDER BY id;
GO
CREATE VIEW teacher_bilocation_list AS
SELECT TOP 100 PERCENT id, first_name, last_name
FROM Teacher
WHERE dbo.teacher_overlapping_meetings(id) = 1
ORDER BY id;
GO
CREATE VIEW translator_bilocation_list AS
SELECT TOP 100 PERCENT id, first_name, last_name
FROM Translator
WHERE dbo.translator_overlapping_meetings(id) = 1
ORDER BY id;
GO
CREATE VIEW master_list AS
SELECT Student.id, Student.first_name, Student.last_name, Studies.id, Studies.title
FROM Student
INNER JOIN StudentStudies ON StudentStudies.student_id = Student.id AND
StudentStudies.certificate_post_date IS NOT NULL
INNER JOIN Studies ON Studies.id = StudentStudies.studies_id;
GO
CREATE VIEW graduates_without_diploma AS
SELECT id, first_name, last_name
FROM Student
INNER JOIN StudentStudies ON Student.id = StudentStudies.student_id AND
StudentStudies.credit_date IS NOT NULL AND
StudentStudies.certificate_post_date IS NULL
UNION
SELECT id, first_name, last_name
FROM Student
INNER JOIN StudentCourse ON Student.id = StudentCourse.student_id AND
StudentCourse.credit_date IS NOT NULL AND
StudentCourse.certificate_post_date IS NULL;
GO
CREATE VIEW room_bilocation_list AS
SELECT TOP 100 PERCENT id, building, number
FROM Room
WHERE dbo.room_overlapping_meetings(id) = 1;
GO
CREATE VIEW pending_payments
AS
SELECT Basket.id,
CAST(SUM(dbo.basket_item_price(BasketItem.course_id, BasketItem.meeting_id,
BasketItem.studies_id,
BasketItem.webinar_id)) / 100.0 AS DECIMAL(10, 2)) AS price
FROM Basket
INNER JOIN BasketItem ON BasketItem.basket_id = Basket.id
WHERE state = 'pending_payment'
GROUP BY Basket.id;
GO