以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.net/bbs/index.asp)
--  专家坐堂  (http://foxtable.net/bbs/list.asp?boardid=2)
----  如何根据性别统计男职与女职生人数  (http://foxtable.net/bbs/dispbbs.asp?boardid=2&id=43697)

--  作者:ybc76
--  发布时间:2013/12/13 8:12:00
--  如何根据性别统计男职与女职生人数
这个汇总的代码如何把条件加进去啊,就是统计性别=‘女’的人数,和性别=‘男’的人数
Dim t As Table = Tables("ryda")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Count
g.GroupOn = "*"
g.TotalOn = "姓名"
g.Caption = "人数"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Count
g.GroupOn = "*"
g.TotalOn = "性别"
g.Caption = "女工"
t.SubtotalGroups.Add(g)

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Count
g.GroupOn = "*"
g.TotalOn = "性别"
g.Caption = "男工"
t.SubtotalGroups.Add(g)


--  作者:狐狸爸爸
--  发布时间:2013/12/13 8:34:00
--  

命令窗口执行:

 

Dim t As Table = Tables("表A")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True

g = New Subtotalgroup
g.Aggregate = AggregateEnum.Count
g.GroupOn = "*"
g.Caption = "总计"
t.SubtotalGroups.Add(g)

t.Subtotal()

Dim r As Row = t.Rows(t.Rows.Count(True)-1, True)
Dim n As Integer = t.Compute("Count(姓名)","性别 = \'男\'")
r("性别") = "男:" & n & ",女:" & (t.rows.count - n)


 

参考:

http://www.foxtable.com/help/topics/1594.htm

http://www.foxtable.com/help/topics/1911.htm

http://www.foxtable.com/help/topics/1964.htm

[此贴子已经被作者于2013-12-13 8:35:56编辑过]

--  作者:Bin
--  发布时间:2013/12/13 8:37:00
--  
汇总模式是不可以设置条件的
你可以考虑使用代码自定义汇总的方式.

--  作者:ybc76
--  发布时间:2013/12/13 9:51:00
--  
这代码还是有问题,统计的不对!!!
图片点击可在新窗口打开查看此主题相关图片如下:1.jpg
图片点击可在新窗口打开查看

--  作者:狐狸爸爸
--  发布时间:2013/12/13 9:52:00
--  

这个是因为没有输入性别的,就当做女的了,你可以直接修改我二楼的代码,先理解一下,再修改


--  作者:ybc76
--  发布时间:2013/12/13 10:02:00
--  
我改成这样,结果正确。
Dim t As Table = Tables("ryda")
Dim g As Subtotalgroup
t.SubtotalGroups.Clear()
t.GroupAboveData = False
t.TreeVisible = False
t.SpillNode = True
g = New Subtotalgroup
g.Aggregate = AggregateEnum.Count
g.GroupOn = "*"
g.TotalOn = "姓名"
g.Caption = "人数"
t.SubtotalGroups.Add(g)
t.Subtotal()
Dim r As Row = t.Rows(t.Rows.Count(True)-1, True)
Dim n As Integer = t.Compute("Count(姓名)","性别 = \'男\'")
Dim m As Integer = t.Compute("Count(姓名)","性别 = \'女\'")
r("组织名称") = "男:" & n & ",女:" & m & ""