如果楼主是想求表1与表2,通过zifu11=zifu12,累计cnt_zifu11 为A1,累计cnt_zifu12 为B1,累计cnt_zifu11与cnt_zifu12 的最小值为 Num1的话
估计 B1=0要放在 for v=1 to 4 的前面,如
B1=0
for v=1 to 4
*下面用SQL连接来验证
CREATE CURSOR zifubiao1(zifu11 C(6),cnt_zifu11 N(4))
INSERT INTO zifubiao1(zifu11,cnt_zifu11) values('a1',47)
INSERT INTO zifubiao1(zifu11,cnt_zifu11) values('a2',35)
INSERT INTO zifubiao1(zifu11,cnt_zifu11) values('a3',53)
INSERT INTO zifubiao1(zifu11,cnt_zifu11) values('a4',24)
INSERT INTO zifubiao1(zifu11,cnt_zifu11) values('a5',40) &&多出的记录
CREATE CURSOR zifubiao2(zifu12 C(6),cnt_zifu12 N(4))
INSERT INTO zifubiao2(zifu12,cnt_zifu12) values('a4',23)
INSERT INTO zifubiao2(zifu12,cnt_zifu12) values('a3',47)
INSERT INTO zifubiao2(zifu12,cnt_zifu12) values('a2',60)
INSERT INTO zifubiao2(zifu12,cnt_zifu12) values('a1',42)
INSERT INTO zifubiao2(zifu12,cnt_zifu12) values('a6',82) &&多出的记录
SET EXACT OFF
A1=0
B1=0
Num1=0
for u=1 to 4
sele zifubiao1
go u
X=cnt_zifu11
A1=A1+cnt_zifu11
C=zifu11
b1=0
for v=1 to 4
sele zifubiao2
go v
Y=cnt_zifu12
B1=B1+cnt_zifu12
D=zifu12
if C=D
Num1=Num1+min(X,Y)
endif
endfor
ENDFOR
xiangsidu1=2*Num1/(A1+B1)
?"方法1:",TRANSFORM(a1),TRANSFORM(b1),TRANSFORM(xiangsidu1)
*连接表,找出最小值
SELECT a.*,b.*,IIF(,,) as min_cnt FROM zifubiao1 a;
left join zifubiao2 b ON a.zifu11=b.zifu12 INTO CURSOR biao3
SELECT SUM(cnt_zifu11) as A1,SUM(cnt_zifu12) as B1,SUM(min_cnt) as Num1 FROM biao3 WHERE !ISNULL(zifu12) INTO CURSOR biao4
SELECT biao4
xiangsidu1=2*Num1/(A1+B1)
?"方法2:",TRANSFORM(a1),TRANSFORM(b1),TRANSFORM(xiangsidu1)