以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  最近三个月平均值  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=178081)

--  作者:nuoyan89
--  发布时间:2022/6/17 8:34:00
--  最近三个月平均值
老师,我想在表事件中定个代码,根据使用机床,成品编码等在油料表中计算最近三个月的使用平均值。
--  作者:有点蓝
--  发布时间:2022/6/17 8:47:00
--  
参考:http://www.foxtable.com/webhelp/topics/0158.htm


--  作者:nuoyan89
--  发布时间:2022/6/17 8:59:00
--  
老师,我是想写成下面这样的代码,只是下面这个是求和的

        If e.DataCol.Name  = "成品编码" OrElse e.DataCol.Name = "使用设备"  Then
            Dim Filter2 As String = "[成品编码] = \'" & e.DataRow("成品编码") & "\' and [使用设备] = \'" & e.DataRow("使用设备") & "\' "
            e.DataRow("报废品") = DataTables("过程异常明细").SQLCompute("Sum(异常数量)", Filter2)
        End If

--  作者:有点蓝
--  发布时间:2022/6/17 9:02:00
--  
http://www.foxtable.com/webhelp/topics/0099.htm
--  作者:nuoyan89
--  发布时间:2022/6/17 9:03:00
--  
老师,最近三个月这个条件怎么写呢?
--  作者:有点蓝
--  发布时间:2022/6/17 9:14:00
--  
http://www.foxtable.com/webhelp/topics/0259.htm


--  作者:nuoyan89
--  发布时间:2022/6/17 10:04:00
--  

老师,请帮忙看看,谢谢

图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

Dim d As Date = Date.Today.Month 
Dim dt1 As Date = d.AddMonths(-3) \'减去10个月
If e.DataCol.Name = "使用设备"  Then
    If  e.DataRow("使用设备") = Nothing Then
        e.DataRow("油料费用") = Nothing
    Else
        Dim Filter2 As String = "[使用设备] = \'" & e.DataRow("使用设备") & "\' and [使用设备] = \'" & e.DataRow("使用设备") & "\' and [月] < \'" & d & "\'and [月] > = \'" & dt1 & "\'"
        e.DataRow("油料费用") = DataTables("油料成本明细").SQLCompute("Avg(单价成本)", Filter2)
    End If
End If

--  作者:有点蓝
--  发布时间:2022/6/17 10:15:00
--  
Dim d As Date = Date.Today

多看看帮助,不要蒙着用:http://www.foxtable.com/webhelp/topics/0250.htm