Dim dt As DataTable = DataTables("表A") Dim dt2 As DataTable = DataTables("表B") dt2.DataRows.Clear Dim ss() As String = {"政治面貌","性别"} For Each lb As String In ss Dim dr As DataRow= dt2.AddNew dr("类别")=" " & lb Dim sum() As Double = {0,0,0,0,0} For Each s As String In dt.GetValues(lb,lb & " is not null") dr = dt2.AddNew dr("类别")=" "&s dr("人数")=dt.Compute("count(姓名)", lb & "='" & s & "'") dr("综合办")=dt.Compute("count(姓名)", lb & "='" & s & "' and 部门='综合办'") dr("销售部")=dt.Compute("count(姓名)", lb & "='" & s & "' and 部门='销售部'") dr("业务部")=dt.Compute("count(姓名)", lb & "='" & s & "' and 部门='业务部'") dr("财务部")=dt.Compute("count(姓名)", lb & "='" & s & "' and 部门='财务部'") sum(0) += dr("人数") sum(1) += dr("综合办") sum(2) += dr("销售部") sum(3) += dr("业务部") sum(4) += dr("财务部") Next dr = dt2.AddNew dr("类别") = "合计" dr("人数")=sum(0) dr("综合办")=sum(1) dr("销售部")=sum(2) dr("业务部")=sum(3) dr("财务部")=sum(4) Next
|