Foxtable(狐表)用户栏目专家坐堂 → [分享]利用SQLGroupTableBuilder作年龄段分组统计。


  共有6408人关注过本帖树形打印复制链接

主题:[分享]利用SQLGroupTableBuilder作年龄段分组统计。

帅哥哟,离线,有人找我吗?
pc005637
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1038 积分:12915 威望:0 精华:0 注册:2011/5/29 15:19:00
[分享]利用SQLGroupTableBuilder作年龄段分组统计。  发帖心情 Post By:2013/4/16 16:47:00 [只看该作者]

数据源:MSSQL2000

外部表名:"xxx"

统计用到的列:"年龄"\"锁定"\"审核状态"

 

 "年龄分组"
        Dim old As String
        Dim n As Integer = 5 '年龄段划分的区间值
        Dim p As Integer = 20 '年龄段的区间数目
        For i As Integer = 0 To p
            Dim d As String = Format(i * n,"000") & "-" & Format((i + 1) * n - 1,"000")
            If i = 0 Then
                old = "(Case When 年龄 < " & (i + 1) * n & " Then '" & d & "'"
            ElseIf i = p Then
                old = old & " When 年龄 < " & (i + 1) * n & " Then '" & d & "' Else '大于" & (i + 1) * n & "' End)"
            Else
                old = old & " When 年龄 < " & (i + 1) * n & " Then '" & d & "'"
            End If
        Next
       
        Dim nl1 As New SQLGroupTableBuilder("统计表1","xxx")
        nl1.C
        nl1.Groups.AddExp("年龄段", old)
        nl1.Totals.AddDef("锁定", AggregateEnum.Count, "未审核")
        nl1.Filter = "审核状态 = '未审核'"
        Dim dsnl1 As fxDataSource
        dsnl1 = nl1.BuildDataSource()
       
        Dim nl2 As New SQLGroupTableBuilder("统计表2","xxx")
        nl2.C
        nl2.Groups.AddExp("年龄段", old)
        nl2.Totals.AddDef("锁定", AggregateEnum.Count, "已审核")
        nl2.Filter = "审核状态 = '已审核'"
        nl2.GrandProportion = True
        Dim dsnl2 As fxDataSource
        dsnl2 = nl2.BuildDataSource()
       
        dsnl1.Combine("年龄段",dsnl2,"年龄段")
        Dim t_nl As Table = Tables("窗口A_Table1")
        t_nl.DataSource = dsnl1
        Dim g_nl As Subtotalgroup
        t_nl.SubtotalGroups.Clear()
        g_nl = New Subtotalgroup '定义一个新的分组
        g_nl.Aggregate = AggregateEnum.Sum '统计类型为求和
        g_nl.GroupOn = "*" '分组列
        g_nl.TotalOn = "未审核,已审核" '设置统计列
        g_nl.Caption = "小计" '设置标题
        t_nl.Sort = "年龄段"
        t_nl.SubtotalGroups.Add(g_nl) '加到分组集合中
        t_nl.Subtotal() '生成汇总模式
        t_nl.AutoSizeCols
        Forms("窗口A").Controls("Table1").Visible = True
        DataTables("窗口A_Table1").SysStyles("Alternate").BackColor = Color.PowderBlue


 回到顶部
帅哥哟,离线,有人找我吗?
pc005637
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1038 积分:12915 威望:0 精华:0 注册:2011/5/29 15:19:00
[注意]如果数据表是内部表。  发帖心情 Post By:2013/4/16 16:49:00 [只看该作者]

应该用IIF() 函数作区分。

 回到顶部