SELECT t1.ID,ROUND(sum(t1.gpax)/sum(cast(t1.CR_HR as int )),2) FROM
(
SELECT scoreed.ID, scoreed.YRSM, scoreed.GRADE,scoreed.CR_HR,
(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) as GPA,(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) *scoreed.CR_HR as GPAX
FROM [transcripts].[dbo].[scoreed]
where scoreed.ID=49111180 and cast(scoreed.YRSM as INT) BETWEEN 481 and 481 and
((scoreed.GRADE)<>'W' And (scoreed.GRADE)<>'NP' And (scoreed.GRADE)<>'P')
) as t1
GROUP BY t1.ID
Code (SQL)
SELECT t2.ID,ROUND(sum(t2.gpax)/sum(cast(t2.CR_HR as int )),2) FROM
(
SELECT scoreed.ID, scoreed.YRSM, scoreed.GRADE,scoreed.CR_HR,
(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) as GPA,(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) *scoreed.CR_HR as GPAX
FROM [transcripts].[dbo].[scoreed]
where scoreed.ID=49111180 and cast(scoreed.YRSM as INT) BETWEEN 481 and 482 and
((scoreed.GRADE)<>'W' And (scoreed.GRADE)<>'NP' And (scoreed.GRADE)<>'P')
) as t2
GROUP BY t2.ID
ใช้ join มีข้อความ error
Msg 8155, Level 16, State 2, Line 36
No column name was specified for column 2 of 'xx'.
Msg 8155, Level 16, State 2, Line 70
No column name was specified for column 2 of 'xxx'.
แก้ไขอย่างไร
Code (SQL)
SELECT xx.ID
FROM
(
SELECT t1.ID,ROUND(sum(t1.gpax)/sum(cast(t1.CR_HR as int )),2) FROM
(
SELECT scoreed.ID, scoreed.YRSM, scoreed.GRADE,scoreed.CR_HR,
(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) as GPA,(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) *scoreed.CR_HR as GPAX
FROM [transcripts].[dbo].[scoreed]
where scoreed.ID=49111180 and cast(scoreed.YRSM as INT) BETWEEN 481 and 481 and
((scoreed.GRADE)<>'W' And (scoreed.GRADE)<>'NP' And (scoreed.GRADE)<>'P')
) as t1
GROUP BY t1.ID
) as xx
INNER JOIN
(
SELECT t2.ID,ROUND(sum(t2.gpax)/sum(cast(t2.CR_HR as int )),2) FROM
(
SELECT scoreed.ID, scoreed.YRSM, scoreed.GRADE,scoreed.CR_HR,
(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) as GPA,(case scoreed.GRADE
when 'A' then 4
when 'B+' then 3.5
when 'B' then 3
when 'C+' then 2.5
when 'C' then 2
when 'D+' then 1.5
when 'D' then 1
when 'F' then 0
else 0
end
) *scoreed.CR_HR as GPAX
FROM [transcripts].[dbo].[scoreed]
where scoreed.ID=49111180 and cast(scoreed.YRSM as INT) BETWEEN 481 and 482 and
((scoreed.GRADE)<>'W' And (scoreed.GRADE)<>'NP' And (scoreed.GRADE)<>'P')
) as t2
GROUP BY t2.ID
) as xxx
ON xx.ID = xxx.ID