select id,no,sum(value) from table1 where no=''1980'' union select count(id),count(no),sum(value) from table1 where no=''1980''
谢谢,能在说清楚点吗?求和的edit用那个字段赋值? grid里显示哪几个字段?
我上面的写的有点错误 建议字段名别和关键字重名 tempa//表名 select id,no1,value1 from tempa where no1=1 union select '总和','',sum(value1) from tempa where no1=1 order by id结果 ------------------------------------------------------- id no1 value1 1 1 4 2 1 6 3 1 9 总和 19 ------------------------------------------------------- procedure TForm1.Button1Click(Sender: TObject); begin with adoquery1 do begin last; showmessage(inttostr(fieldbyname('value1').AsInteger));///19 end; end;
union
select count(id),count(no),sum(value) from table1 where no=''1980''
把两个查询结果全并起来
union
select count(id),count(no),sum(value) from table1 where no=''1980''
grid里显示哪几个字段?
建议字段名别和关键字重名
tempa//表名
select id,no1,value1 from tempa where no1=1
union
select '总和','',sum(value1) from tempa where no1=1
order by id结果
-------------------------------------------------------
id no1 value1
1 1 4
2 1 6
3 1 9
总和 19
-------------------------------------------------------
procedure TForm1.Button1Click(Sender: TObject);
begin
with adoquery1 do
begin
last;
showmessage(inttostr(fieldbyname('value1').AsInteger));///19
end;
end;
table_fin(id,bflag,bno,bvalue,bdate,buser)
//字段依次为:帐目编号,有效标记,合同编号,金额,日期,经办人 //这个是用来写sql的函数
procedure SetQFi(str: string);
begin
with Datamodule1.Q_Fi do
begin
close;
sql.Clear;
sql.Add('SELECT * ');
sql.Add('FROM table_fin ');
sql.Add('where ');
sql.Add('bflag=true ');
sql.Add('and bno=:bno ');
sql.Add('union');
sql.Add('select sum(bvalue) as bvalue FROM table_fin');
sql.Add('where ');
sql.Add('bflag=true ');
sql.Add('and bno=:bno ');
Parameters.ParamValues['bno']:=str;
open; end;
end; 这样出错,说不正常的定义参数对象,提供了不完整或不一致的信息