此主题相关图片如下:421.png
在研究FT的经典例子中,遇到一个问题,计算及格率、优秀率时,要是“化学”学科没有考试,即“成绩表”中“化学”列的数值是空值,按照下列的代码计算的及格率,优秀率全部出现0.00%,这种情况怎么处理呢,能不能让没有考试的“化学”及格率、优秀率为空值呢?
Dim b As New SQLGroupTableBuilder("统计表1","成绩表")
b.Groups.AddDef("班级")
b.Totals.AddExp("人数","学号","",AggregateEnum.Count) '统计人数
Dim nms()
As
String =
{"语文","英语","数学","物理","化学"}
For
Each
nm As
String
In nms '利用表达式统计及格人数和优秀人数
b.Totals.Addexp(nm
& "_及格", "iif(" & nm & " >= 60, 1,
0)")
b.Totals.Addexp(nm & "_优秀", "iif(" & nm & " >= 90, 1,
0)")
Next
b.VerticalTotal = True
b.Build()
For
Each nm As
String
In nms '对生成的统计表增加表达式列,计算及格率和优秀率
DataTables("统计表1").DataCols.Add(nm & "_及格率",Gettype(Double), nm
& "_及格/人数"
)
Tables("统计表1").Cols(nm &
"_及格率").Move(Tables("统计表1").Cols(nm &
"_及格").Index +
1)
DataTables("统计表1").DataCols.Add(nm & "_优秀率",Gettype(Double), nm
& "_优秀/人数"
)
Tables("统计表1").Cols(nm &
"_优秀率").Move(Tables("统计表1").Cols(nm &
"_优秀").Index +
1)
DataTables("统计表1").DataCols(nm &
"_及格率").SetFormat("0.00%")
DataTables("统计表1").DataCols(nm &
"_优秀率").SetFormat("0.00%")
Next
MainTable = Tables("统计表1")
[此贴子已经被作者于2018/5/13 14:55:48编辑过]