Y yyss Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-01 #1 对adoquery1的float型字段a求和,除以adoquery1记录数,结果复制给adoquery2的float型字段b,代码怎么写?
C creation-zy Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-01 #2 var<br> Sumouble;<br> RecMark,Count:Integer;<br>begin<br> Sum:=0;<br> with adoquery1 do<br> begin<br> Count:=RecordCount;<br> RecMark:=RecNo;<br> DiableControls;<br> First;<br> while not Eof do<br> begin<br> Sum:=Sum+FieldByName('a').AsFloat;<br> Next;<br> end;<br> RecNo:=RecMark;<br> EnableControls;<br> end;<br> if Count>0 then<br> adoquery2.FieldByName('b').AsFloat:=Sum/Count;<br>end;
var<br> Sumouble;<br> RecMark,Count:Integer;<br>begin<br> Sum:=0;<br> with adoquery1 do<br> begin<br> Count:=RecordCount;<br> RecMark:=RecNo;<br> DiableControls;<br> First;<br> while not Eof do<br> begin<br> Sum:=Sum+FieldByName('a').AsFloat;<br> Next;<br> end;<br> RecNo:=RecMark;<br> EnableControls;<br> end;<br> if Count>0 then<br> adoquery2.FieldByName('b').AsFloat:=Sum/Count;<br>end;
李 李翔鹏 Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-02 #3 select a,avg(a) as b from table1
Y yyss Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-02 #4 Sum是Double型,Count是Integer型,能运算吗?<br>我这样不可以:<br>adoquery2.FieldByName('bzzs').AsFloat:=sum(FieldByName('ljzs')/adoquery1.RecordCount;
Sum是Double型,Count是Integer型,能运算吗?<br>我这样不可以:<br>adoquery2.FieldByName('bzzs').AsFloat:=sum(FieldByName('ljzs')/adoquery1.RecordCount;
L luoyanqing119 Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-03 #5 adoquery1.fieldbyname ('b').asfloat:=<br> adoquery1.fieldbyname ('a').asfloat/adoquery1.recordcount<br>后边adoquery1.recordcount是INT类型的,将自动转换,不会有什么问题的.还有要保证数据以经SELECT出来了.
adoquery1.fieldbyname ('b').asfloat:=<br> adoquery1.fieldbyname ('a').asfloat/adoquery1.recordcount<br>后边adoquery1.recordcount是INT类型的,将自动转换,不会有什么问题的.还有要保证数据以经SELECT出来了.
Y yyss Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-03 #6 adoquery2.FieldByName('bzzs').AsFloat:=sum(FieldByName('ljzs').AsFloat)/adoquery1.RecordCount;<br>提示需要变量,sum(FieldByName('ljzs').AsFloat)有错误,怎么写
adoquery2.FieldByName('bzzs').AsFloat:=sum(FieldByName('ljzs').AsFloat)/adoquery1.RecordCount;<br>提示需要变量,sum(FieldByName('ljzs').AsFloat)有错误,怎么写
H hanpengshan_00 Unregistered / Unconfirmed GUEST, unregistred user! 2008-06-04 #7 delphi里那里有sum函数,我服了你,补充下<br>var<br> Sumouble;<br> RecMark,Count:Integer;<br>begin<br> Sum:=0;<br> with adoquery1 do<br> begin<br> Count:=RecordCount;<br> RecMark:=RecNo;<br> DiableControls;<br> First;<br> while not Eof do<br> begin<br> Sum:=Sum+FieldByName('a').AsFloat;<br> Next;<br> end;<br> RecNo:=RecMark;<br> EnableControls;<br> end;<br> if Count>0 then<br> begin<br> adoquery2.Edit; //注意必须先定位到你要的记录,还有数据集必须打开<br> adoquery2.FieldByName('b').AsFloat:=Sum/Count;<br> adoquery2.Post;<br> end; <br>end;
delphi里那里有sum函数,我服了你,补充下<br>var<br> Sumouble;<br> RecMark,Count:Integer;<br>begin<br> Sum:=0;<br> with adoquery1 do<br> begin<br> Count:=RecordCount;<br> RecMark:=RecNo;<br> DiableControls;<br> First;<br> while not Eof do<br> begin<br> Sum:=Sum+FieldByName('a').AsFloat;<br> Next;<br> end;<br> RecNo:=RecMark;<br> EnableControls;<br> end;<br> if Count>0 then<br> begin<br> adoquery2.Edit; //注意必须先定位到你要的记录,还有数据集必须打开<br> adoquery2.FieldByName('b').AsFloat:=Sum/Count;<br> adoquery2.Post;<br> end; <br>end;