|
So you can choose the field name at will, but if you want to change the calculated column, modify the value of the corresponding I in the code
Use aaa Alias MyTest
For I=2 To 13&&to obtain the total number of columns 2 and 13 (except for the 11th)
If I<>11
lcString1='Select Distinct'+Field(I,'MyTest')+' Into Cursor Dist_'+Field(I,'MyTest')+' From aaa'
&lcString1
Endif
Endfor
I=1&&to find the sum of the first column
lcString2='select sum('+Field(I,'MyTest')+') as'+Field(I,'MyTest')+'and'
for I=2 to 10&&Find the number of each number in the second column to the tenth column
Select'Dist_'+Field(I,'MyTest')
Scan
lcString2=lcString2+',sum(iif('+Field(I,'MyTest')+'='+Transform(Evaluate(Field(1)))+',1,0)) as'+Field(I,' MyTest')+Transform(Evaluate(Field(1)))
Endscan
endfor
lcString2=lcString2+' into table table1 from aaa'
&lcString2&&Generate table 1 table1
browse&&take a look
lcString3='select '
I=12&&Find the sum of the 11th column of the numbers in the 12th column
Select'Dist_'+Field(I,'MyTest')
Scan
lcString3=lcString3+'sum(iif('+Field(1)+'='+Transform(Evaluate(Field(1)))+","+Field(I-1,'MyTest')+',0)) as'+Field(I-1,'MyTest')+Transform(Evaluate(Field(1)))+','
EndScan
I=13&&Find the sum of the 14th column of the numbers in the 13th column
Select'Dist_'+Field(I,'MyTest')
Scan
lcString3=lcString3+'sum(iif('+Field(1)+'='+Transform(Evaluate(Field(1)))+","+Field(I+1,'MyTest')+',0)) as'+Field(I+1,'MyTest')+Transform(Evaluate(Field(1)))+','
EndScan
lcString3=left(lcString3,len(lcString3)-1)+' into table table2 from aaa'
&lcString3&&Generate table 2 table2
browse&&take a look
select table1.*,table2.* into table BBB from table1,table2&&to generate your result table BBB.DBF
browse&&take a look |
|