以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助] 统计代码  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=31809)

--  作者:bahamute
--  发布时间:2013/4/21 0:18:00
--  [求助] 统计代码
想从B表统计A表数据:因使用多层表头,结构比较复杂,故手工统计,不想编码遇到问题:
一、按单位统计男女人数。
二、按单位统计年龄介于35-45之间人数。
代码该怎么写,单位易表用惯了,记得好像find函数就能解决,到了狐表居然就抓瞎了。
请求协助。

Dim dr As DataRow = e.DataRow

Dim dt As DataTable =DataTables("基本信息")

If e.DataCol.Name = "单位" And dr.IsNull("单位") = False Then

dr("人数") = dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\'")  ‘这一句到时统计出数据了,但老感觉不对,是不是条件字段反了? 

dr("男性") = dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\'" And [性别] ="\'&男&"\'")   ’帮忙

dr("35-45")=dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\'" And [年龄]............)   ‘帮忙

end if


[此贴子已经被作者于2013-4-21 0:19:24编辑过]

--  作者:bahamute
--  发布时间:2013/4/21 10:04:00
--  
以下是引用muhua在2013-4-21 9:25:00的发言:

Dim dr As DataRow = e.DataRow
Dim dt As DataTable =DataTables("基本信息")
If e.DataCol.Name = "单位" And dr.IsNull("单位") = False Then
    dr("人数") = dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\'")  \'这一句到时统计出数据了,但老感觉不对,是不是条件字段反了?
    dr("男性") = dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\' And [性别] =\'" & 男 & "\'")   \'帮忙
    dr("35-45")= dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\' And [年龄] >= 35 And 年龄 <=45")   \'帮忙
End If

 



会提示未声明名称“男”
[此贴子已经被作者于2013-4-21 10:04:42编辑过]

--  作者:don
--  发布时间:2013/4/21 10:16:00
--  

 dr("男性") = dt. Compute("Count(姓名)","[单位] = \'" & dr("单位") & "\' And [性别] =\'男\'")