以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]计算平均值时,结果全是0  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=177836)

--  作者:moseser
--  发布时间:2022/6/7 7:40:00
--  [求助]计算平均值时,结果全是0
代码如下:

Dim t As Table = Tables("整理_table2")
Dim n As Integer = t.Count
For i As Integer = 0 To n - 1
    Dim x As Integer = t.Rows(i)("序列号")
    Dim avg As Double = t.Compute("avg(综合单价)", "序列号 = x " )
    t.Rows(i)("平均单价") = avg
Next

是不是”序列号 = x“ ,写的有问题?

--  作者:狐狸爸爸
--  发布时间:2022/6/7 8:03:00
--  
Dim t As Table = Tables("整理_table2")
Dim n As Integer = t.Count
For i As Integer = 0 To n - 1
    Dim x As Integer = t.Rows(i)("序列号")
    Dim avg As Double = t.Compute("avg(综合单价)", "序列号 = \'" & x & "\'" )
    t.Rows(i)("平均单价") = avg
Nex

参考: