-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquestion and query.sql
145 lines (93 loc) · 5.88 KB
/
question and query.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
use [Student Assesment Database];
-- Give list of students (id,name,section and gender ) which are taught by a given instructor in a given semster
select Student.sid, Student.fname,Student.lname,Student.section,Student.gender from Student
join Registration on Student.sid = Registration.sid where Registration.INSTID like 'inst005%' and Registration.semester = '1';
--maintain continous assessment results
select * from Assesment where Assesment.SID like 'st001%' and Assesment.COURSE like 'Acct1020%' and Assesment.[Assesment name] like 'Final%';
--or
update Assesment
set weight='30',result='15',[assesment date]='2022-06-06'
where Assesment.SID='st010' and COURSE='Cosc4060' and [Assesment name]='MID Exam'
--List of students that are absent in a particular assessment
select * from Assesment where Assesment.result is NULL;
--continuous assessment result of a student in a given course for a specified semester and year
select Assesment.SID,Assesment.COURSE, [Assesment name] ,weight,result,semester,registration_year from Assesment join Registration on
Registration.sid=Assesment.SID and Registration.code=Assesment.COURSE
where Assesment.SID like 'st001%' and Assesment.COURSE like 'Acct1020%' and semester like '2%' and Registration.registration_year like '2005-01-01%';
--Summary of continuous assessment result of a given student for a specified course that includes full assessment informaion
select COURSE , SUM(result) as 'Total' from Assesment join Registration on
Registration.sid=Assesment.SID and Registration.code=Assesment.COURSE
where Assesment.SID like 'st001%' and COURSE like 'Acct1020%' group by COURSE
--Which course the students scored an 'F'
SELECT Assesment.SID,Assesment.COURSE ,SUM(result) as 'Total' , Grade='F'
FROM Assesment group by COURSE,SID having SUM(result)<45 and SUM(result)>=35;
--list of students along with the total number of main courses,common courses and elective course they took
select Registration.sid,course.type, COUNT(*) as 'Total Number of Courses' from Registration join
course on Registration.code =course.code group by type,Registration.sid;
--List of students along with the number of 'A's,'B's etc they scored so far
--list of instructors along with course titles and semester and year they teach each course
select Instructor.INSTID as 'Instructor id',Instructor.fname,Instructor.lname,course.title,Registration.semester,Registration.registration_year
from Instructor join Registration on Instructor.INSTID = Registration.INSTID join course on Registration.code=course.code;
use [Student Assesment Database]
--tools
select COURSE ,SUM(result) as 'Total' from Assesment join Registration on
Registration.sid=Assesment.SID and Registration.code=Assesment.COURSE
where Assesment.SID like 'st001%' and semester like '2%' group by COURSE
-- to calculate total in assesment table
select SID,COURSE,COALESCE(SUM(result),0)as 'TOTAL' from Assesment group by COURSE,SID
--to calculate grade
select Registration.Grade from Registration where exists
(SELECT Grade=
CASE
when SUM(result)> 90 Then 'A+'
WHEN SUM(result)>=80 and SUM(result)<90 THEN 'A'
WHEN SUM(result)>=70 and SUM(result)<80 THEN 'B+'
WHEN SUM(result)>=65 and SUM(result)<70 THEN 'B'
WHEN SUM(result)>=60 and SUM(result)<65 THEN 'C+'
WHEN SUM(result)>=55 and SUM(result)<60 THEN 'C'
WHEN SUM(result)>=45 and SUM(result)<55 THEN 'D'
WHEN SUM(result)<45 and SUM(result)>=35 THEN 'F'
ELSE 'NG'
END
FROM Assesment group by COURSE,SID);
update Registration
set Grade (select * from temp);
select COURSE , SUM(result) as 'Total' from Assesment join Registration on
Registration.sid=Assesment.SID and Registration.code=Assesment.COURSE
where Assesment.SID like 'st001%' and semester like '2%' group by COURSE
SELECT Assesment.SID,Assesment.COURSE ,grade=
CASE
when SUM(result)> 90 Then 'A+'
WHEN SUM(result)>=80 and SUM(result)<90 THEN 'A'
WHEN SUM(result)>=70 and SUM(result)<80 THEN 'B+'
WHEN SUM(result)>=65 and SUM(result)<70 THEN 'B'
WHEN SUM(result)>=60 and SUM(result)<65 THEN 'C+'
WHEN SUM(result)>=55 and SUM(result)<60 THEN 'C'
WHEN SUM(result)>=45 and SUM(result)<55 THEN 'D'
WHEN SUM(result)<45 and SUM(result)>=35 THEN 'F'
ELSE 'NG'
END
FROM Assesment join Registration on Registration.code=Assesment.COURSE and Registration.sid=Assesment.SID group by COURSE,Assesment.SID
select (select course.title from course join Registration on Registration.code=course.code) from Registration
---fuck this
select course.code from course where course.code not in (select course.code from course join Registration on Registration.code = course.code
join Assesment on Assesment.SID=Registration.sid and Assesment.COURSE=Registration.code where [Assesment name] like 'assignment%');
select * from Registration left outer join Assesment on Registration.sid=Assesment.SID and Registration.code=Assesment.COURSE
where
SELECT Assesment.SID,Assesment.COURSE, grade=
CASE
when SUM(result)> 90 Then 'A+'
WHEN SUM(result)>=80 and SUM(result)<90 THEN 'A'
WHEN SUM(result)>=70 and SUM(result)<80 THEN 'B+'
WHEN SUM(result)>=65 and SUM(result)<70 THEN 'B'
WHEN SUM(result)>=60 and SUM(result)<65 THEN 'C+'
WHEN SUM(result)>=55 and SUM(result)<60 THEN 'C'
WHEN SUM(result)>=45 and SUM(result)<55 THEN 'D'
WHEN SUM(result)<45 and SUM(result)>=35 THEN 'F'
ELSE 'NG'
END
FROM Assesment group by COURSE,SID;
SELECT Assesment.SID,Assesment.COURSE ,SUM(result) as 'Total' , Grade='F'
FROM Assesment group by COURSE,SID having SUM(result)<45 and SUM(result)>=35;
select type,COUNT(*) as 'total' from Registration join course on Registration.code=course.code group by type;
selec