1、你给的数据里,排名是班级的排名,而不是年级的排名。
2、代码这样写
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 Then
Dim filter As String = "年级 = '" & dr("年级") & "' and 班级 = '" & dr("班级") & "'"
Dim filter1 As String = "年级 = '" & dr("年级") & "'"
dr("班级人数") = dt.Compute("Count(姓名)", filter)
dr("年级优秀人数") = dt.Compute("Count(姓名)*0.25",filter1)
Dim filter2 As String = filter & " and " & dr("学科") & "排名 <= " & dr("年级优秀人数")
dr("班级学科年级排名人数") = dt.Compute("count(姓名)", filter2)
dr("优秀率") = dr("班级学科年级排名人数") / dr("年级优秀人数")
End If
End Select