CLEAR
CLOSEall
SET SAFETY OFF
DIMENSION YB(7,5)
USE 原表
select * from 原表 into array YB FOR i=1 TO 7 FOR j=1 TO 5 ?? YB(i,j) ENDFOR ? ENDFOR USE 行全排列表 *----------------------- BH=0 FOR i=1 TO 7 APPEND BLANK BH=BH+1 FOR j=1 TO 5 REPLACE编号 WITHBH REPLACE('列'+ALLTRIM(STR(j))) WITHYB(i,j) ENDFOR ENDFOR *-----------------------------
DELETE FILE *.bak
select 1 as 列号,recn() as 行号,A as 数据列 from T1
union all
select 2 as 列号,recn() as 行号,B as 数据列 from T1
union all
select 3 as 列号,recn() as 行号,C as 数据列 from T1
union all
select 4 as 列号,recn() as 行号,D as 数据列 from T1
union all
select 5 as 列号,recn() as 行号,E as 数据列 from T1
Create Cursor tt (x C(1))
For lnI=1 to 7
Insert into tt values (Chr(64+lnI))
EndFor
Select a.x+","+b.x+","+c.x+","+d.x+","+e.x+","+f.x+","+g.x h from tt a ;
inner join tt b on not InList(b.x,a.x) ;
inner join tt c on not InList(c.x,a.x,b.x) ;
inner join tt d on not InList(d.x,a.x,b.x,c.x) ;
inner join tt e on not InList(e.x,a.x,b.x,c.x,d.x) ;
inner join tt f on not InList(f.x,a.x,b.x,c.x,d.x,e.x) ;
inner join tt g on not InList(g.x,a.x,b.x,c.x,d.x,e.x,f.x) into cursor temp
Select * from 原表 where .f. into cursor 新表 readwrite
Select Chr(64+Recno()) bz,* from 原表 into cursor yb
Select temp
Scan
=ALines(ab,h,",")
For lni=1 to ALines(ab,h,",")
Insert into 新表 select 列1,列2,列3,列4,列5 from yb where bz==ab[lni]
endfor
Insert into 新表 (列1) values (0)
EndScan
Select 新表
browse
CLEAR
CLOSEall
SET SAFETY OFF
DIMENSION YB(7,5)
USE 原表
select * from 原表 into array YB FOR i=1 TO 7 FOR j=1 TO 5 ?? YB(i,j) ENDFOR ? ENDFOR USE 行全排列表 *----------------------- BH=0 FOR i=1 TO 7 APPEND BLANK BH=BH+1 FOR j=1 TO 5 REPLACE编号 WITHBH REPLACE('列'+ALLTRIM(STR(j))) WITHYB(i,j) ENDFOR ENDFOR *-----------------------------
DELETE FILE *.bak
我这里不讨论算法,只是为了得出结果:
CLOSE DATABASES
CREATE CURSOR 原表 (a c(2),b c(2),c c(2),d c(2),e c(2))
INSERT INTO 原表 (a,b,c,d,e) VALUES ('1','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('2','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('3','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('4','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('5','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('6','B','C','D','E')
INSERT INTO 原表 (a,b,c,d,e) VALUES ('7','B','C','D','E')
GO TOP IN 原表
SELECT * FROM 原表 INTO CURSOR 新表 WHERE .f. READWRITE&&原表可换你的表
FOR I1=1 TO 7 FOR I2=1 TO 7 IF i2<>i1 FOR I3=1 TO 7 IF i3<>i2 AND i3<>i1 FOR I4=1 TO 7 IF i4<>i3 AND i4<>i2 AND i4<>i1 FOR I5=1 TO 7 IF i5<>i4 AND i5<>i3 AND i5<>i2 AND i5<>i1 FOR I6=1 TO 7 IF i6<>i5 AND i6<>i4 AND i6<>i3 AND i6<>i2 AND i6<>i1 FOR I7=1 TO 7 IF i7<>i6 AND i7<>i5 AND i7<>i4 AND i7<>i3 AND i7<>i2 AND i7<>i1 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I1 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I2 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I3 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I4 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I5 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I6 INSERT INTO 新表 SELECT * FROM 原表 WHERE RECNO()=I7 APPEND BLANK IN 新表 ENDIF ENDFOR ENDIF ENDFOR ENDIF ENDFOR ENDIF ENDFOR ENDIF ENDFOR ENDIF ENDFOR
ENDFOR
SELECT 新表
BROWSE