以文本方式查看主题 - Foxtable(狐表) (http://foxtable.net/bbs/index.asp) -- 专家坐堂 (http://foxtable.net/bbs/list.asp?boardid=2) ---- [求助] 增加求总条件 (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=188006) |
-- 作者:sanny -- 发布时间:2023/8/26 11:37:00 -- [求助] 增加求总条件 老师,如表,增加了个列”具体日期“, 只要具体日期相同的只计算一次相同产品,以下代码该如何修改,谢谢。 Dim dt As DataTable = DataTables("表C") Dim C As List(Of String()) C = dt.GetValues("月份|产品","产品 is not null") Dim dr As DataRow For Each Customer As String() In C dr = dt.find("[月份] = \'" & Customer (0) & "\' and 产品=\'" & Customer (1) & "\'") dr("总数量") = dt.Compute("Sum(数量)","[月份] = \'" & Customer(0) & "\' and 产品=\'" & Customer(1) & "\'") dr("产品重复笔数") = dt.Compute("COUNT(产品)","[月份] = \'" & Customer(0) & "\' and 产品=\'" & Customer(1) & "\'") Next |
-- 作者:夜点蚊香 -- 发布时间:2023/8/26 11:40:00 -- Dim dt As DataTable = DataTables("表C") Dim C As List(Of String()) C = dt.GetValues("月份|产品","产品 is not null") Dim dr As DataRow For Each Customer As String() In C dr = dt.find("[月份] = \'" & Customer (0) & "\' and 产品=\'" & Customer (1) & "\'") dr("总数量") = dt.Compute("DISTINCT SUM(数量)","[月份] = \'" & Customer(0) & "\' and 产品=\'" & Customer(1) & "\'") dr("产品重复笔数") = dt.Compute("COUNT(DISTINCT 产品)","[月份] = \'" & Customer(0) & "\' and 产品=\'" & Customer(1) & "\'") Next
|
-- 作者:sanny -- 发布时间:2023/8/26 11:44:00 -- 出错了, 另也没有把具体日期考虑进去。 [此贴子已经被作者于2023/8/26 11:44:43编辑过]
|
-- 作者:有点蓝 -- 发布时间:2023/8/26 11:55:00 -- dr("产品重复笔数") = dt.getvalues("具体日期","[月份] = \'" & Customer(0) & "\' and 产品=\'" & Customer(1) & "\'").count |