ID Semester GPA Center NAme Date Check in
ID 1 Fall 3.0 A Center - 11/3/2000
ID 1 Fall 3.0 A Center - 11/4/2000
ID 1 Spring 3.5 B Center - 3/3/2000
ID 2 Fall 3.0 B Center - 11/5/2000
ID 3 Fall 3.0 C Center - 11/1/2000
ID 3 spring 3.2 C Center - 3/3/2000
ID 4 Fall 3.2 D Center - 11/10/2000
ID 4 Spring 3.0 D Center - 3/11/2000
.
.
.
...
寻找哪些辅导中心对学生更有效;哪个中心可以帮助学生增加学生的学习成绩。 GPA。
我想得到如下结果。
ID -- Different GPA -- Center
ID3 -- 0.2 --C Center
ID4 -- -0.4 --D Center
.
.
.
所以我知道C中心比D中心更有效。
我在下面的每个ID中找到了春季和秋季学期之间不同GPA的代码。但是,我想按中心分组。
select DISTINCT(a.[Fake ID]),
b.GPA - a.GPA as diff
from tutor a
join tutor b on a.[Fake ID] = b.[Fake ID]
where a.Semester = 'Fall'
and b.Semester = 'Spring'
ORDER BY [Fake ID] DESC;
答案 0 :(得分:0)
SELECT t.Id, t.Center, spring.Gpa - fall.Gpa
FROM tutor t
INNER JOIN tutor fall
ON t.ID = fall.ID AND fall.Semester='Fall' AND fall.Center = t.Center
INNER JOIN tutor spring
ON t.ID = spring.ID AND spring.Semester='Sprint' AND spring.Center = t.Center
SELECT t.Id, t.Center, spring.Gpa - fall.Gpa
FROM tutor t
INNER JOIN tutor fall
ON t.ID = fall.ID AND fall.Semester='Fall' AND fall.Center = t.Center
INNER JOIN tutor spring
ON t.ID = spring.ID AND spring.Semester='Sprint' AND spring.Center = t.Center