还可以将统计条件保存在表中
坚守VFP最后的阵地
clear close databases all select bm from bmb into cursor tbmb && BM表只有一个字段 * 创建临时表结构及索引 lcstr="" scan lcstr=lcstr+alltrim(bm)+" N(3)," endscan lcstr=left(lcstr,len(lcstr)-1) create cursor tjb (序 n(2),文化程度 c(20),dm c(2),人数 n(4),&lcstr) append from 表1 fields 序,文化程度,dm index on dm tag dmxl * 数据处理 use gxb in 0 && 保存统计条件的表(字段:TJ,WZ) use hmd in 0 && 花名册 select hmd set relation to dm into tjb Scan bm1=Alltrim(bm) Replace (bm1) with Evaluate(bm1)+1 in tjb EndScan set relation to Select gxb scan * 列人数合计 select tjb Local asj[reccount("gxb"),Fcount()-4] For i=5 to Fcount() Sum evaluate(Field(i)) to asj[recno("gxb"),i-4] for evaluate(gxb.tj) replace (Field(i)) with asj[recno("gxb"),i-4] for Recno()=gxb.wz EndFor endscan select tjb * 行人数合计 cstr="" For i=5 to Fcount() cstr=cstr+"+"+(Field(i)) EndFor Replace all 人数 with Evaluate(cstr) browse
[此贴子已经被作者于2016-12-22 01:10编辑过]
clear close databases all select * from bmb into cursor tbmb * 创建临时表结构及索引 lcstr="" scan lcstr=lcstr+alltrim(bm)+" N(3)," endscan lcstr=left(lcstr,len(lcstr)-1) create cursor tjb (序 n(2),文化程度 c(20),dm c(2),人数 n(4),&lcstr) append from 表1 fields 序,文化程度,dm index on dm tag dmxl * 数据处理 use gxb in 0 use hmd in 0 select hmd set relation to dm into tjb Scan bm1=Alltrim(bm) Replace (bm1) with Evaluate(bm1)+1 in tjb EndScan set relation to n=4 && 前四个字段不参与统计 Select gxb scan * 列人数合计 select tjb Local asj[reccount("gxb"),Fcount()-n] For i=n+1 to Fcount() Sum evaluate(Field(i)) to asj[recno("gxb"),i-n] for evaluate(gxb.tj) replace (Field(i)) with asj[recno("gxb"),i-n] for Recno()=gxb.wz EndFor endscan select tjb * 行人数合计 cstr="" For i=n+1 to Fcount() cstr=cstr+"+"+(Field(i)) EndFor Replace all 人数 with Evaluate(cstr) browse