或者这样写:var i:integer; ss:double; begin adoquery1.first; for i:=1 to adpquery1.recordcount do begin ss:=ss+adoquery1.fieldbyname('pay').AsFloat; adoquery1.next; end; end;你试一下,不知道是否可以。
如果判断zt为1的个数,也好办。 var i,k:integer; ss:double; begin adoquery1.first; ss:=0.0; k:=0; for i:=1 to adpquery1.recordcount do begin ss:=ss+adoquery1.fieldbyname('pay').AsFloat; if adoquery1.fieldbyname('zt').asstring=1 then k:=K+1; adoquery1.next; end; showmessage('pay的总数为:’+floattostr(ss) + 'zt为1的个数为:'+inttostr(k)); end;
To dingding2005:首先是用SQL查询,然后才有RecordCount的么。不知道你是怎么写的,能写出来看看么?
用count()得到个数,sum()得到总数
adoquery1.sql.add('select count(*),sum(pay) from table where zt=''1''');
笨方法:在query中用循环一条条判断累加。 first; while not eof do begin if ...then 进行累加 end;其实,直接用SQL语句要快得多。
beginend;是不是在这个中间写代码呢?
i:integer;
ss:double;
begin
adoquery1.first;
for i:=1 to adpquery1.recordcount do
begin
ss:=ss+adoquery1.fieldbyname('pay').AsFloat;
adoquery1.next;
end;
end;你试一下,不知道是否可以。
var
i,k:integer;
ss:double;
begin
adoquery1.first;
ss:=0.0;
k:=0;
for i:=1 to adpquery1.recordcount do
begin
ss:=ss+adoquery1.fieldbyname('pay').AsFloat;
if adoquery1.fieldbyname('zt').asstring=1 then
k:=K+1;
adoquery1.next;
end;
showmessage('pay的总数为:’+floattostr(ss) + 'zt为1的个数为:'+inttostr(k));
end;
first;
while not eof do
begin
if ...then
进行累加
end;其实,直接用SQL语句要快得多。