自己编码生成临时表来统计
Dim dtb As New DataTableBuilder("坯料统计")
dtb.AddDef("客户", Gettype(String), 16)
dtb.AddDef("合金", Gettype(String), 16)
dtb.AddDef("坯料规格", Gettype(String), 30)
dtb.AddDef("生产批号", Gettype(String), 30)
dtb.AddDef("总数", Gettype(Integer))
dtb.AddDef("当前规格_7", Gettype(Integer),"","7.0")
dtb.AddDef("当前规格_4", Gettype(Integer),"","4.0")
dtb.AddDef("当前规格_18", Gettype(Integer),"","1.8")
dtb.AddDef("当前规格_18Q", Gettype(Integer),"","1.8已切")
dtb.AddDef("当前规格_1", Gettype(Integer),"","1.0")
dtb.AddDef("当前规格_05", Gettype(Integer),"","0.5")
dtb.AddDef("当前规格_03", Gettype(Integer),"","0.3")
dtb.Build()
For Each nm() As String In DataTables("坯料跟踪表").GetUniqueValues("","客户","合金","坯料规格","生产批号")
Dim dr As DataRow = DataTables("坯料统计").AddNew()
dr("客户") = nm(0)
dr("合金") = nm(1)
dr("坯料规格") = nm(2)
dr("生产批号") = nm(3)
dr("当前规格_7") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '7.0'")
dr("当前规格_4") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '4.0'")
dr("当前规格_18") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '1.8'")
dr("当前规格_18Q") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '1.8Q'")
dr("当前规格_1") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '1.0'")
dr("当前规格_05") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '0.5'")
dr("当前规格_03") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "' And [当前规格] = '0.3'")
dr("总数") = DataTables("坯料跟踪表").Compute("COUNT(熔铸编号)","[客户] = '" & nm(0) & "' And [合金] = '" & nm(1) & "' And [坯料规格] = '" & nm(2) & "' And [生产批号] = '" & nm(3) & "'")
Next