Dim dr As DataRow = e.DataRow
Dim dt As DataTable =DataTables("学生成绩")
Select Case e.DataCol.name
Case "名称", "年级", "班级", "科目"
If dr.IsNull("名称") = False AndAlso dr.IsNull("年级") = False AndAlso dr.IsNull("班级") = False AndAlso dr.IsNull("科目") = False Then
Dim filter As String = "名称= '" & dr("名称") & "' and 年级 = '" & dr("年级") & "' and 班级 = '" & dr("班级") & "'"
dr("最高分") = dt.Compute("Max(" & dr("科目") & ")", filter)
dr("最低分") = dt.Compute("Min(" & dr("科目") & ")", filter)
dr("平均分") = dt.Compute("Avg(" & dr("科目") & ")", filter)
dr("成绩分布_0分") = dt.Compute("Count(姓名)", dr("科目") & " = 0 and " & filter)
dr("成绩分布_0至9分") = dt.Compute("Count(姓名)", dr("科目") & " > 0 And " & dr("科目") & " < 10 and " & filter)
dr("成绩分布_10至19分") = dt.Compute("Count(姓名)", dr("科目") & " >= 10 And " & dr("科目") & " < 20 and " & filter)
dr("成绩分布_20至29分") = dt.Compute("Count(姓名)", dr("科目") & " >= 20 And " & dr("科目") & " < 30 and " & filter)
dr("成绩分布_30至39分") = dt.Compute("Count(姓名)", dr("科目") & " >= 30 And " & dr("科目") & " < 40 and " & filter)
dr("成绩分布_40至49分") = dt.Compute("Count(姓名)", dr("科目") & " >= 40 And " & dr("科目") & " < 50 and " & filter)
dr("成绩分布_50至59分") = dt.Compute("Count(姓名)", dr("科目") & " >= 50 And " & dr("科目") & " < 60 and " & filter)
dr("成绩分布_60至69分") = dt.Compute("Count(姓名)", dr("科目") & " >= 60 And " & dr("科目") & " < 70 and " & filter)
dr("成绩分布_70至79分") = dt.Compute("Count(姓名)", dr("科目") & " >= 70 And " & dr("科目") & " < 80 and " & filter)
dr("成绩分布_80至89分") = dt.Compute("Count(姓名)", dr("科目") & " >= 80 And " & dr("科目") & " < 90 and " & filter)
dr("成绩分布_90至99分") = dt.Compute("Count(姓名)", dr("科目") & " >= 90 And " & dr("科目") & " < 100 and " & filter)
dr("成绩分布_100分") = dt.Compute("Count(姓名)", dr("科目") & " = 100 and " & filter)
dr("成绩分布_100至119分") = dt.Compute("Count(姓名)", dr("科目") & " > 100 And " & dr("科目") & " < 120 and " & filter)
dr("成绩分布_120分") = dt.Compute("Count(姓名)", dr("科目") & " = 120 and " & filter)
dr("及格人数") = dt.Compute("Count(姓名)", dr("科目") & " >= 60 and " & filter)
dr("不及格人数") = dt.Compute("Count(姓名)", dr("科目") & " < 60 and " & filter)
dr("考试人数") = dt.Compute("Count(姓名)", dr("科目") & " >= 0 and " & filter)
dr("均分值") = dr("平均分") * 0.7 + dr("及格率") * 20 + dr("优秀率") *10
dr("优秀率") = dt.Compute("Count(姓名)", dr("科目") & " >= 85") / dt.Compute("Count(姓名)")
dr("及格率") = dt.Compute("Count(姓名)", dr("科目") & " >= 60") / dt.Compute("Count(姓名)")
End If
End Select
计算出来有问题题具体在标色的,不能每个班不同的的及格率与优秀率。如下图这两列的数据一样,不能每个班不同的的及格率与优秀率
此主题相关图片如下:newscreen25494619.jpg
按钮代码
Dim dt2 As DataTable = DataTables("成绩分布")
dt2.DataRows.Clear() '清除原有数据
Dim dt As DataTable = DataTables("学生成绩")
Dim kms() As String = {"语文","数学","英语","物理","化学","政治","历史","地理","生物"}
For Each ary() As String In dt.GetValues("名称|年级|班级")
For Each km As String In kms
Dim ndr As DataRow = dt2.AddNew
ndr("名称") = ary(0)
ndr("年级") = ary(1)
ndr("班级") = ary(2)
ndr("科目") = km
Next
Next
Messagebox.Show("统计完毕!")
[此贴子已经被作者于2019/5/5 14:30:37编辑过]