[英]SQL create new table and insert data from another table
我試圖找出每學期GPA的差異。
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
因為ID 2沒有春季GPA,所以我無法在兩個學期之間進行比較。 因此,我應該如何寫出ID 1和ID 3的GPA差異?
ID 1 : .5
ID 3 : .2
自我加入:
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';
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.