-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.sql
111 lines (97 loc) · 4.15 KB
/
main.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
select points from scores where assignmentID=31;
SELECT MAX(POINTS) FROM scores WHERE assignmentID=31;
SELECT MIN(POINTS) FROM scores WHERE assignmentID=31;
SELECT AVG(POINTS) FROM scores WHERE assignmentID=31;
SELECT s.*
FROM registration e
JOIN students s ON e.studentID = s.studentID
WHERE e.courseID = 3;
SELECT st.*, s.fName, s.lName, s.major
FROM scores st
JOIN students s ON s.studentID = st.studentID
JOIN registration e ON e.studentID = st.studentID
WHERE e.courseID=3;
INSERT into assignments (distributionID, instance, pointsPossible) VALUES (1, 5, 200);
select * from distribution;
update distribution
set percent=35
where distributionID=12;
select * from distribution;
update distribution
set percent=25
where distributionID=16;
select * from distribution;
select * from scores where assignmentID=5;
UPDATE scores
SET points = points + 2
WHERE assignmentID = 5;
select * from scores where assignmentID=5;
select * from scores where assignmentID=53;
select * from students where studentID=5;
UPDATE scores st
join students s on s.studentID = st.studentID
set points = points + 2
where assignmentID = 53
and s.lName like '%Q%';
select * from scores where assignmentID=53;
/* get count */
select count(*) from scores s left join assignments a on s.assignmentID = a.assignmentID join distribution d on d.distributionID = a.distributionID where courseID=3 and studentID=1
group by d.distributionID;
select * from scores s left
join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1;
/* task11 */
select sum((s.points/a.pointsPossible) * (d.percent/c.counter)) as final_grade
from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
join (select d.distributionID, count(*) as counter from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1 group by d.distributionID)
c on c.distributionID= d.distributionID
where courseID=3
and studentID=1;
/* experiment */
select if(
(d.category='Project' and s.points/a.pointsPossible<=lw.low),
'true', 'false')
from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
join (select d.distributionID, count(*) as counter from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1 group by d.distributionID)
c on c.distributionID= d.distributionID
join (select d.distributionID, min(s.points/a.pointsPossible) as low from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1 group by d.distributionID)
lw on lw.distributionID= d.distributionID
where courseID=3
and studentID=1;
/* task12 */
select sum(
if(
(d.category='Project' and s.points/a.pointsPossible<=lw.low),
d.percent/c.counter,
(s.points/a.pointsPossible) * (d.percent/c.counter)
)
) as final_grade
from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
join (select d.distributionID, count(*) as counter from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1 group by d.distributionID)
c on c.distributionID= d.distributionID
join (select d.distributionID, min(s.points/a.pointsPossible) as low from scores s
left join assignments a on s.assignmentID = a.assignmentID
join distribution d on d.distributionID = a.distributionID
where courseID=3 and studentID=1 group by d.distributionID)
lw on lw.distributionID= d.distributionID
where courseID=3
and studentID=1;