具體的SQL查詢語句跟資料結構有關,不同的資料結構實現語句會有很大的不同,大致思路是篩選出語文、數學、英語三科的成績,然後用得分人分組求和。下面舉幾個例子供參考:
1)單表結構
Scores(SName,CName,Score)
SQL實現語句
select SName,avg(Score) as avgScore from Scores
where CName in ("語文","英語","數學") group by SName ;
2)多表結構
Students(SID,SName)
Courses(CID,CName) 假設語文、數學、英語的CID分別是001,002,003
Scores(SID,CID,Score)
Students的SID,Courses的CID分別與Scores的SID和CID建立一對多參照完整性關係
select b.SName,a.avgScore from
(select SID,avg(Score) as avgScore from Scores
where CID in ("001","002","003") group by SID)a, Students b
where a.SID=b.SID;
具體的SQL查詢語句跟資料結構有關,不同的資料結構實現語句會有很大的不同,大致思路是篩選出語文、數學、英語三科的成績,然後用得分人分組求和。下面舉幾個例子供參考:
1)單表結構
Scores(SName,CName,Score)
SQL實現語句
select SName,avg(Score) as avgScore from Scores
where CName in ("語文","英語","數學") group by SName ;
2)多表結構
Students(SID,SName)
Courses(CID,CName) 假設語文、數學、英語的CID分別是001,002,003
Scores(SID,CID,Score)
Students的SID,Courses的CID分別與Scores的SID和CID建立一對多參照完整性關係
SQL實現語句
select b.SName,a.avgScore from
(select SID,avg(Score) as avgScore from Scores
where CID in ("001","002","003") group by SID)a, Students b
where a.SID=b.SID;