循环问题,大哥们帮忙看看 急
var
a,b:double;
i:integer;
begin
adoquery6.SQL.Clear;
adoquery6.SQL.Text:=' SELECT * FROM (SELECT 仪表档案编号 AS 仪表档案编号1, MAX(抄表时间) AS 抄表时间1 FROM roompower GROUP BY 仪表档案编号) t1 LEFT OUTER JOIN roompower ON t1.仪表档案编号1 = roompower.仪表档案编号 AND t1.抄表时间1= roompower.抄表时间 ' ;
adoquery6.Open;
adoquery6.First;
while not adoquery6.Eof do
begin
for i:=1 to adoquery6.RecordCount do
begin
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from power where 抄表时间 >=#'+formatdateTime('yyyy-mm-dd',now-2)+'# and 抄表时间<#'+formatdateTime('yyyy-mm-dd',now)+'# and 仪表档案编号=i');
adoquery2.Open;
edit6.Text:=adoquery2.fieldbyname('抄表数据').AsString ;
adoquery2.Close;
adoquery2.SQL.Clear;
adoquery2.SQL.Add('select * from power where 抄表时间 >=#'+formatdateTime('yyyy-mm-dd',now-12)+'# and 抄表时间<#'+formatdateTime('yyyy-mm-dd',now)+'# and 仪表档案编号=i ');
adoquery2.Open;
edit7.Text:=adoquery2.fieldbyname('抄表数据').AsString ;
a:=strtofloat(edit6.Text);
b:=strtofloat(edit7.Text);
edit5.Text:=floattostr(abs(a-b)/10);
adoquery10.Close;
adoquery10.SQL.Clear;
adoquery10.SQL.Add('update 用户信息 set 平均电量=abs(a-b)/10 where 住房编号=i');
adoquery10.ExecSQL;
adoquery6.Next
end;
end;
end;