|
发表于 2020-7-25 10:30:01
|
显示全部楼层
这样你随意起字段名了,不过如果要改变计算的列,修改代码中相应I的值
Use aaa Alias MyTest
For I=2 To 13 &&得出第2列和第13列的共有那些数(第11除外)
If I<>11
lcString1='Select Distinct '+Field(I,'MyTest')+' Into Cursor Dist_'+Field(I,'MyTest')+' From aaa'
&lcString1
Endif
Endfor
I=1 &&求第1列的和用
lcString2='select sum('+Field(I,'MyTest')+') as '+Field(I,'MyTest')+'和'
for I=2 to 10 &&求第2列至第10列各个数的个数
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 &&生成表1 table1
browse &&看一下
lcString3='select '
I=12 &&求第12列各个数时第11列的和
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 &&求第13列各个数时第14列的和
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 &&生成表2 table2
browse &&看一下
select table1.*,table2.* into table BBB from table1,table2 &&生成你的结果表BBB.DBF
browse &&看一下 |
|