exec sql declare c1 cursor for select * from tb1 group by xu;
exec sql open;
do{ exec sql open c1 into :zh1,:xu,:cg;
if(sqlca.sqlcode==100) break;
exec sql declare c2 cursor for select * from tb1 where xu=:xu;
exec sql open;
do{ exec sql open c2 into :zh2,:xu,:cg;
if(sqlca.sqlcode==100) break;
if(strcmp(zh1,zh2)!=0){
exec sql declare c3 cursor for select * from tb1 where xu=:xu;
exec sql open;
int i=0,j=0;
do{ exec sql open c3 into :zh2,:xu,:cg;
if(sqlca.sqlcode==100) break;
if(cg==1) i++,j++;
if(cg==2) j++;
printf("序号%d的成功率=%f\n",xh,i/j);
}while(1);
exec sql close c3;
}
else {printf("序号%d的概率=0\n",xh);break;}
}while(1);
exec sql close c2;
}while(1)
exec sql close c1;
select zh , xh,[rate] = sum(case cg when 1 then 1.0 when 2 then 0.0 end)/(sum(case cg when 1 then 0 when 2 then 1 end) +sum(case cg when 1 then 1.0 when 2 then 0.0 end))
from sucess group by zh,xh order by zh,xh