Rss & SiteMap
Foxtable(狐表) http://www.foxtable.com
你是要这样的结果吗?:::::
dim b As New SQLGroupTableBuilder("统计表1","jlj")
b.Groups.AddDef("批次")
b.Totals.AddDef("合格蛋数")
b.Exprs.Adddef("产蛋率","[合格蛋数]/[存栏母鸡]")
b.Exprs.Adddef("入舍鸡产蛋率","[合格蛋数]/[进栏母鸡]")
b.build
with DataTables("统计表1")
.DataCols.Add("淘汰", GetType(Integer))
End With
For Each r As Row In Tables("统计表1").Rows
r("淘汰") = DataTables("jlj").Compute("Sum(淘汰)", "批次 = '" & r("批次") & "'")
Next
Tables("窗口1_Table1").DataSource = DataTables("统计表1")
Tables("窗口1_Table1").Cols("淘汰").Move(1)
Maintable = Tables("统计表1")
dim n as integer = CurrentTable.Count
Dim Sum As Integer = DataTables("统计表1").Compute("Sum(产蛋率)")
Dim Sum1 As Integer = DataTables("统计表1").Compute("Sum(入舍鸡产蛋率)")
CurrentTable.AddNew()
currenttable.current("批次") = "平均数"
currenttable.current("产蛋率") = Sum/n
currenttable.current("入舍鸡产蛋率") = Sum1/n
结果:
dim b As New SQLGroupTableBuilder("统计表1","jlj")
b.Groups.AddDef("批次")
b.Totals.AddDef("合格蛋数")
b.build
with DataTables("统计表1")
.DataCols.Add("淘汰", GetType(Integer))
.DataCols.Add("产蛋率", GetType(Double))
.DataCols.Add("入舍鸡产蛋率", GetType(Double))
End With
Tables("统计表1").Cols("淘汰").Move(1)
Maintable = Tables("统计表1")
Tables("窗口1_Table1").DataSource = DataTables("统计表1")
Tables("窗口1_Table1").Cols("淘汰").Move(1)
For i as integer = 0 to Tables("统计表1").count -1
dim r as row = Tables("统计表1").Rows(i)
dim n0 as integer = DataTables("jlj").Compute("Count(产蛋率)", "批次 = '" & r("批次") & "'")
dim n as integer = DataTables("jlj").Compute("Count(入舍鸡产蛋率)", "批次 = '" & r("批次") & "'")
Dim Sum As Double = DataTables("jlj").Compute("Sum(产蛋率)", "批次 = '" & r("批次") & "'")
Dim Sum1 As Double = DataTables("jlj").Compute("Sum(入舍鸡产蛋率)", "批次 = '" & r("批次") & "'")
r("淘汰") = DataTables("jlj").Compute("Sum(淘汰)", "批次 = '" & r("批次") & "'")
r("产蛋率") = Sum/n0
r("入舍鸡产蛋率") = Sum1/n '这是简单算术平均数,加权平均数公式自己搞定吧。
Next
结果:
此主题相关图片如下:未命名1.jpg
但不知为何? 第二次执行时,会提示错误,说:不存在产蛋率和入舍产蛋率两列??? 郁闷啊~
为何?=》Tables("窗口1_Table1")所在窗口要是关闭后重新打开就不会提示了~ ?