我一直在尝试将我的MIS表格中的Quiz1,Quiz2,Exam1和Exam2字段的平均值加入到我的学生表中。
这是每张桌子的内容。
MIS包含以下字段:StudentID,QUIZ1,QUIZ2,EXAM1,EXAM2和ClassID
学生有专业,学生ID,学生参与
我想要完成的是两件事:
1。)将MIS表加入学生表 2.)获得测验1和2以及考试1和2的平均值。
预期结果是这样的:
专业---学生评论--- Quiz1Avg --- Quiz2Avg --- Exam1Avg --- Exam2Avg
到目前为止我尝试过:
Private Sub Query2_Enter(sender As Object, e As EventArgs) Handles Query2.Enter
Dim DC As New OleDbConnection("provider=microsoft.ACE.oledb.12.0;data source=HogCountryUniversity.accdb")
Dim DS As New DataSet()
'Joined mis and students but don't know how to get the averages (working)'
Dim DA As New OleDbDataAdapter("Select major, studstanding, quiz1, quiz2, exam1, exam2 from [mis] inner join [students] on [mis].studentid = [students].studentid", DC)
'Display average of Quiz1 from mis table(working)'
'Dim DA As New OleDbDataAdapter("Select classid, formatnumber(avg(quiz1),2) as [Quiz1Avg] from mis group by classid", DC)
'Not working'
'Dim DA As New OleDbDataAdapter("Select students.major, students.studstanding, quiz1, quiz2, exam1, exam2 from [mis] inner join on [students].studentid = [mis].studentid", DC)
'Not working'
'Dim DA As New OleDbDataAdapter("Select students.major, students.studstanding, avg(mis.quiz1) as [Quiz1Avg] from quiz1 mis inner join students on mis.studentid = students.studentid group by mis.classid", DC)
DC.Open()
DA.Fill(DS)
DataGridView2.DataSource = DS.Tables(0).DefaultView()
DC.Close()
End Sub
我知道如何从一个表中获取一个字段的平均值并加入表格,但我不知道如何加入这两个表并获得上述字段的平均值。
我真的被卡住了,看了不同的堆栈溢出示例,但我仍然没有得到它。任何帮助/指示/推动/勺子喂养都非常感谢!
谢谢!
编辑:
我明白了!
Dim DA As New OleDbDataAdapter("Select students.major, students.studstanding, formatnumber(avg(mis.quiz1),2) as Quiz1Avg, formatnumber(avg(mis.quiz2),2) as Quiz2Avg, formatnumber(avg(mis.exam1),2) as Exam1Avg, formatnumber(avg(mis.exam2),2) as Exam2Avg from students inner join mis on students.studentid = mis.studentid group by students.major, students.studstanding", DC)