表格列转行
品种 机号A 5
B 4
A 1
A 3
A 2
B 6
B 7
我想把表做成:
品种
A 5 1 3 2
B 4 6 7
请问用VFP怎么实现?高,谢谢!
CREATE CURSOR test (品种 c(1), 机号 n(1)) INSERT INTO test VALUES ("A", 5) INSERT INTO test VALUES ("B", 4) INSERT INTO test VALUES ("A", 1) INSERT INTO test VALUES ("A", 3) INSERT INTO test VALUES ("A", 2) INSERT INTO test VALUES ("B", 6) INSERT INTO test VALUES ("B", 7) SELECT 品种, COUNT(*) lnCnt FROM test GROUP BY 1 ORDER BY 2 DESC INTO ARRAY aa lcStr = "品种 c(1)" FOR ln = 1 TO aa[1,2] lcStr = lcStr + ", S" + TRANSFORM(ln) + " n(1)" ENDFOR CREATE CURSOR t1 (&lcStr) && 保存最后结果 INSERT INTO t1 (品种) SELECT DISTINCT 品种 FROM test INDEX ON 品种 TAG t1 CREATE CURSOR t2 (品种 c(1), js N(4)) && 记录字段列序号 INSERT INTO t2 (品种) SELECT DISTINCT 品种 FROM test INDEX ON 品种 TAG t2 SELECT test SCAN IF SEEK(test.品种, "t2", "t2") = .T. REPLACE js WITH js + 1 IN t2 ln = t2.js IF SEEK(test.品种, "t1", "t1") = .T. REPLACE ("S" + TRANSFORM(ln)) WITH test.机号 IN t1 ENDIF ENDIF ENDSCAN SELECT t1 BROWSE