1 select UName,
2 (select AVG(Grades) from UserInfo where GName = "語文") as "語文",
3 (select AVG(Grades) from UserInfo where GName = "數學") as "數學",
4 (select AVG(Grades) from UserInfo where GName = "英語") as "英語"
5 from UserInfo
6 where UName = "小明"
7 group by UName
8 /*having GName = "語文" and GName = "數學" and GName = "英語"*/
9 order by AVG(Grades)
10 go
1 select UName,
2 (select AVG(Grades) from UserInfo where GName = "語文") as "語文",
3 (select AVG(Grades) from UserInfo where GName = "數學") as "數學",
4 (select AVG(Grades) from UserInfo where GName = "英語") as "英語"
5 from UserInfo
6 where UName = "小明"
7 group by UName
8 /*having GName = "語文" and GName = "數學" and GName = "英語"*/
9 order by AVG(Grades)
10 go