以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  [求助]交叉统计设置  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=92743)

--  作者:ajie5211
--  发布时间:2016/11/11 15:22:00
--  [求助]交叉统计设置

交叉统计默认出来是这样的
图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161111152110.png
图片点击可在新窗口打开查看

如何转换成这样的?

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


--  作者:有点蓝
--  发布时间:2016/11/11 15:26:00
--  
上例子测试
--  作者:ajie5211
--  发布时间:2016/11/11 15:41:00
--  

 下载信息  [文件大小:   下载次数: ]
图片点击可在新窗口打开查看点击浏览该文件:管理项目2.rar

希望达到效果

图片点击可在新窗口打开查看此主题相关图片如下:qq截图20161111154040.png
图片点击可在新窗口打开查看


--  作者:有点色
--  发布时间:2016/11/11 18:22:00
--  

参考代码

 

Dim dt As DataTable = DataTables("表A")
Dim dtb As New DataTableBuilder("统计")
dtb.AddDef("年", Gettype(String), 16)
dtb.AddDef("周", Gettype(String), 16)
dtb.AddDef("说明", Gettype(String), 16)
Dim prds As List(of String) = dt.GetValues("组别")
For Each prd As String In prds
    dtb.AddDef(prd, Gettype(Double))
Next
dtb.AddDef("合计", Gettype(Double))
dtb.AddDef("调整方案", Gettype(Double))
dtb.Build()
Dim ary_shuoming() As String = {"人数", "产能", "排单量"}
For Each ary() As String In dt.GetValues("年|周")
    For Each shuoming As String In ary_shuoming
        Dim dr As DataRow = DataTables("统计").AddNew()
        dr("年") = ary(0)
        dr("周") = ary(1)
        dr("说明") = shuoming
        Dim sum As Double = 0
        For Each prd As String In prds
            dr(prd) = dt.Compute("sum(" & shuoming & ")", "年 = \'" & ary(0) & "\' and 周 = \'" & ary(1) & "\' and 组别 = \'" & prd & "\'")
            sum += dr(prd)
        Next
        dr("合计") = sum
    Next
Next
With Tables("统计")
    .MergeMode = MergeModeEnum.Standard
    .MergeCols.Clear()
    .MergeCols.Add("年")
    .MergeCols.Add("周")
    .MergeSort = "年,周"
    .AllowMerge = True
End With
MainTable= Tables("统计")

 


--  作者:y2287958
--  发布时间:2016/11/12 12:44:00
--  
我更喜欢这么搞

Dim bm As String = "统计"
Dim jb1 As New SQLJoinTableBuilder(bm,"表A")
jb1.AddCols("年","周","组别","\'人数\' As 分类","人数 as aa")

Dim jb2 As New SQLJoinTableBuilder(bm,"表A")
jb2.AddCols("年","周","组别","\'产能\' As 分类","产能 as aa")

Dim jb3 As New SQLJoinTableBuilder(bm,"表A")
jb3.AddCols("年","周","组别","\'排单量\' As 分类","排单量 as aa")

jb1.Union(jb2)
jb1.Union(jb3)
jb1.Build()

Dim b As New CrossTableBuilder(bm,jb1.BuildSql )
b.HGroups.AddDef("年") 
b.HGroups.AddDef("周") 
b.HGroups.AddDef("分类")
b.VGroups.AddDef("组别")
b.Totals.AddDef("aa")
b.Build
Tables(bm).AutoSizeCols
Tables(bm).MergeMode = MergeModeEnum.Standard
Tables(bm).MergeCols.Clear()
Tables(bm).MergeCols.Add("年")
Tables(bm).MergeCols.Add("周")
Tables(bm).MergeSort = "年,周"
Tables(bm).AllowMerge = True
MainTable = Tables(bm)