-
Notifications
You must be signed in to change notification settings - Fork 0
/
select.sql
178 lines (168 loc) · 5.88 KB
/
select.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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
SELECT DISTINCT snum AS NUM, sname AS NAME \
FROM student s \
WHERE year >= 3 \
AND snum in ( SELECT r1.snum \
FROM mark r1, mark r2 \
WHERE r1.snum = s.snum \
AND r2.snum = s.snum \
AND r1.cnum = 'CS240' \
AND r2.cnum = 'CS245' \
AND r1.grade >= 85 \
AND r2.grade >= 85 \
)
SELECT pnum AS NUM, pname AS NAME \
FROM professor p \
WHERE dept != 'PM' \
AND NOT EXISTS ( SELECT pnum \
FROM class c \
WHERE c.pnum = p.pnum \
AND cnum = 'CS245' \
AND term != 'F2017' \
) \
AND EXISTS ( SELECT * \
FROM class d \
WHERE d.pnum = p.pnum \
AND cnum = 'CS245' \
AND term = 'F2017' )
SELECT snum AS NUM, sname AS NAME, year AS YEAR \
FROM student s \
WHERE snum in ( SELECT snum \
FROM mark \
WHERE cnum = 'CS240' \
ORDER BY grade DESC \
LIMIT 3 )
SELECT snum AS Num, sname AS Name \
FROM student s \
WHERE year > 2 \
AND NOT EXISTS ( SELECT * \
FROM mark m \
WHERE s.snum = m.snum \
AND left(cnum, 2) = 'CS' \
AND grade < 85 ) \
AND NOT EXISTS ( SELECT * \
FROM enrollment e \
WHERE e.snum = s.snum \
AND EXISTS ( SELECT * \
FROM class c \
WHERE c.cnum = e.cnum \
AND c.term = e.cnum \
AND c.section = e.section \
AND EXISTS ( SELECT * \
FROM professor p \
WHERE p.pnum = c.pnum \
AND p.dept != 'CS' ) \
) \
)
SELECT DISTINCT dept AS Department \
FROM professor p \
WHERE EXISTS ( SELECT * \
FROM class c \
WHERE c.pnum = p.pnum \
AND term = 'F2017' \
AND EXISTS ( SELECT * \
FROM schedule sc \
WHERE sc.cnum = c.cnum \
AND sc.term = c.term \
AND sc.section = c.section \
AND sc.day = 'Monday' \
AND left(sc.time, 2) < '12' ) ) \
AND EXISTS ( SELECT * \
FROM class d \
WHERE d.pnum = p.pnum \
AND term = 'F2017' \
AND EXISTS ( SELECT * \
FROM schedule sc \
WHERE sc.cnum = d.cnum \
AND sc.term = d.term \
AND sc.section = d.section \
AND sc.day = 'Friday' \
AND left(sc.time, 2) > '12' ) )
SELECT count(p1.pnum)/count(p2.pnum) AS Ratio \
FROM ( SELECT * \
FROM professor \
WHERE dept = 'PM' ) p1, \
( SELECT * \
FROM professor \
WHERE dept = 'AM' ) p2 \
WHERE EXISTS ( SELECT * \
FROM class c \
WHERE c.pnum = p1.pnum \
AND EXISTS ( SELECT AVG(grade) \
FROM mark m \
WHERE c.cnum = m.cnum \
AND c.term = m.term \
AND c.section = m.section \
HAVING AVG(grade) > 77 ) ) \
AND EXISTS ( SELECT * \
FROM class c \
WHERE c.pnum = p2.pnum \
AND EXISTS ( SELECT AVG(grade) \
FROM mark m \
WHERE c.cnum = m.cnum \
AND c.term = m.term \
AND c.section = m.section \
HAVING AVG(grade) > 77 ) )
SELECT DISTINCT c1.cnum AS CourseNum, c1.term AS Term, \
c1.pnum AS Prof1Num, c2.pnum AS Prof2Num, \
count(e1.snum) AS Prof1Enroll, count(e2.snum) AS Prof2Enroll, \
avg(m1.grade) AS Prof1Avg, avg(m2.grade) AS Prof2Avg \
FROM class c1, class c2, \
enrollment e1, enrollment e2, \
mark m1, mark m2 \
WHERE c1.cnum = c2.cnum \
AND c1.term = c2.term \
AND c1.pnum != c2.pnum \
AND c1.cnum = e1.cnum \
AND c1.term = e1.term \
AND c1.section = e1.section \
AND c2.cnum = e2.cnum \
AND c2.term = e2.term \
AND c2.section = e2.section \
AND c1.cnum = m1.cnum \
AND c1.term = m1.term \
AND c1.section = m1.section \
AND c2.cnum = m2.cnum \
AND c2.term = m2.term \
AND c2.section = m2.section \
GROUP BY c1.cnum, c1.term, c1.pnum, c2.pnum
SELECT term as Term, count( \
(SELECT ee.snum \
FROM enrollment ee \
WHERE ee.cnum NOT IN (SELECT c.cnum \
FROM class c, professor p \
WHERE c.pnum = p.pnum \
AND ( p.dept = 'CO' \
OR p.dept = 'CS' ) ) \
AND ee.term = e.term ) )*100/count(*) \
FROM enrollment e \
GROUP BY e.term \
ORDER BY right(e.term, 4), left(e.term, 1) DESC
SELECT DISTINCT p.pnum AS ProfNum, p.pname AS ProfName, \
c.cnum AS ClassNum, c.term AS Term, c.section AS Section, \
min(m.grade) AS MinGrade, max(m.grade) AS MaxGrade \
FROM mark m, professor p, class c, schedule s \
WHERE c.cnum = s.cnum \
AND c.term = s.term \
AND c.section = s.section \
AND s.day = 'Monday' \
AND s.day = 'Friday' \
AND c.pnum = p.pnum \
AND p.dept = 'CS' \
AND c.cnum = m.cnum \
AND c.term = m.term \
AND c.section = m.section \
GROUP BY p.pnum, p.pname, c.cnum, c.term, c.section
SELECT count(exe.pnum)/count(ampm.pnum)*100 AS Percentage \
FROM (SELECT * \
FROM professor \
WHERE dept = 'AM' \
OR dept = 'PM') ampm, \
(SELECT * \
FROM professor \
WHERE dept = 'AM' \
OR dept = 'PM') exe \
WHERE exe.pnum NOT IN (SELECT c1.pnum \
FROM class c1, class c2 \
WHERE c1.pnum = c2.pnum \
AND c1.term = c2.term \
AND c1.cnum != c2.cnum)