程序代码:
*---VFP9代码
*--- 第一步:先创建一个标准对照表
CREATE CURSOR T (区 C(1),档次 C(2),编号 N(1))
INSERT INTO T VALUES ([a],[高],1)
INSERT INTO T VALUES ([a],[中],2)
INSERT INTO T VALUES ([a],[低],3)
INSERT INTO T VALUES ([b],[高],4)
INSERT INTO T VALUES ([b],[中],5)
INSERT INTO T VALUES ([b],[低],6)
INSERT INTO T VALUES ([c],[高],7)
INSERT INTO T VALUES ([c],[中],8)
INSERT INTO T VALUES ([c],[低],9)
*--- 第二步:生成一个临时数据表(可以省略,这里是示例)
CREATE CURSOR T0 (区 C(1),楼 C(10),档次 C(2),户数 N(3))
INSERT INTO T0 VALUES ([a],[1号楼],[中],20)
INSERT INTO T0 VALUES ([b],[2号楼],[高],10)
INSERT INTO T0 VALUES ([c],[3号楼],[低],30)
INSERT INTO T0 VALUES ([a],[4号楼],[高],10)
INSERT INTO T0 VALUES ([b],[5号楼],[中],30)
INSERT INTO T0 VALUES ([c],[6号楼],[高],50)
INSERT INTO T0 VALUES ([a],[7号楼],[中],10)
INSERT INTO T0 VALUES ([b],[8号楼],[高],20)
INSERT INTO T0 VALUES ([c],[9号楼],[低],30)
*--- 第三步:生成SQL语句
SELECT 区,楼,档次,COUNT(*) 档次合计,SUM(户数) 户数 FROM T0 GROUP BY 区,楼,档次 INTO CURSOR T1
SELECT CAST(B.区 AS C(4)) AS 区,B.档次,NVL(SUM(A.档次合计),0) 档次合计,NVL(SUM(A.户数),0) 户数合计,B.编号 FROM T1 A FULL JOIN T B ON A.区==B.区 AND A.档次==B.档次 GROUP BY B.编号,B.区,B.档次 ORDER BY B.编号 INTO CURSOR T2 READWRITE
INSERT INTO T2 (区,档次合计,户数合计) SELECT [合计],SUM(档次合计),SUM(户数合计) FROM T2
BROWSE
效果图
图片附件: 游客没有浏览图片的权限,请
登录 或
注册