-- SELECT d1 DepPK d1 Name FROM Department d1 Faculty WHERE Faculty Na

 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
-- 5)
SELECT d1.DepPK, d1.[Name]
FROM Department d1, Faculty
WHERE Faculty.[Name] = 'Computer Science' AND
d1.FacFK = Faculty.FacPK
GROUP BY d1.DepPK, d1.[Name]
HAVING (SELECT SUM(Teacher.Salary + Teacher.Commision)
FROM Teacher
WHERE Teacher.DepFK = d1.DepPK AND
Teacher.Post = N'профессор') - 200.00
>
(SELECT SUM(Teacher.Salary + Teacher.Commision)
FROM Department, Teacher
WHERE Department.[Name] = 'SE' AND
Teacher.DepFK = Department.DepPK AND
Teacher.Post = N'ассистент')
-- 6)
SELECT Grp.Num, Tch.Num, Sbj.Num
FROM (SELECT COUNT(Sgroup.Num) AS Num
FROM Sgroup) Grp,
(SELECT COUNT(Teacher.TchPK) AS Num
FROM Teacher) Tch,
(SELECT COUNT([Subject].SbjPK) AS Num
FROM [Subject]) Sbj
-- 7)
SELECT Teacher.[Name] AS [Имя],
(SELECT COUNT(DISTINCT Lecture.SbjFK)
FROM Lecture
WHERE Lecture.TchFK = Teacher.TchPK) AS [количество дисциплин],
(SELECT COUNT(Lecture.TchFK)
FROM Lecture
WHERE Lecture.[Week] = 1 AND
Lecture.TchFK = Teacher.TchPK) AS [количество занятий],
(SELECT COUNT(DISTINCT Lecture.TchFK)
FROM Lecture, Sgroup
WHERE Lecture.[Week] = 2 AND
Lecture.TchFK = Teacher.TchPK
HAVING COUNT(DISTINCT Lecture.GrpFK) <= 3) AS [количество занятий]
FROM Teacher, Department, Faculty
WHERE Faculty.[Name] = 'Informatics' AND
Department.FacFK = Faculty.FacPK AND
Teacher.DepFK = Department.DepPK