Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "elect *From 销售合计 where 年 =" & Format(d2, "yyyy") & " And 月 =" & Format(d2, "MM") & " And 业绩店名 in ('周六福(1)','周六福(2)','周六福(4)','周六福(5)','周六福(7)') "
Dim dt As DataTable = cmd.ExecuteReader
Dim b As New GroupTableBuilder("统计表1", dt)
b.Groups.AddDef("身份证姓名") '根据产品分组
b.Groups.AddDef("业绩店名") '根据产品分组
b.Groups.AddDef("年") '根据产品分组
b.Groups.AddDef("月") '根据产品分组
b.Totals.AddDef("提成主销业绩") '对数量进行统计
b.Totals.AddDef("提成副销业绩")
b.Filter = "身份证姓名 is not null"
Dim dtt As DataTable = b.Build(True) '生成统计表
b = New GroupTableBuilder("统计表2", dt)
b.Groups.AddDef("身份证姓名2") '根据产品分组
b.Groups.AddDef("业绩店名") '根据产品分组
b.Groups.AddDef("年") '根据产品分组
b.Groups.AddDef("月") '根据产品分组
b.Totals.AddDef("提成主销业绩") '对数量进行统计
b.Totals.AddDef("提成副销业绩")
b.Filter = "身份证姓名2 is not null"
Dim dtt2 As DataTable = b.Build(True)
Dim dr As DataRow
For Each dr2 As DataRow In dtt2.DataRows
dr = dtt.Find("身份证姓名='" & dr2("身份证姓名2") & "'")
If dr Is Nothing Then
dr = dtt.AddNew
dr("身份证姓名") = dr2("身份证姓名2")
End If
dr("提成主销业绩") = dr("提成主销业绩") + dr2("提成副销业绩")
Next
dtt.DataCols.Add("合计", GetType(Double), "提成主销业绩")
Dim drs As List(Of DataRow) = dtt.Select("", "合计 desc")
For i As Integer = 0 To math.min(2, drs.count - 1)
dr = drs(i)
Next