I am trying to find the difference of GPA among Semesters.
ID 1 Semester Fall GPA: 3.0
ID 1 Semester Fall GPA: 3.0
ID 1 Semester Spring GPA: 3.5
ID 2 Semester Fall GPA: 3.0
ID 3 Semester Fall GPA: 3.0
ID 3 Semester spring GPA: 3.2
Because ID 2 does not have spring GPA, i would ignore ID2. So, how should i write to find out the difference GPA for ID 1 and ID 3?
ID 1 : .5
ID 3 : .2
I used this code below
select a.id,
b.gpa - a.gpa as diff
from your_table a
join your_table b on a.id = b.id
where a.semester = 'Fall'
and b.semester = 'Spring';
however, the result shows ...
ID1 : .5
ID1 : .5
ID3 : .2
how can I remove the duplication? to get the resut as...
ID1 : .5 ID3 : .2
I am thinking about 'Distinct'?