如何获得表中某字段值的求和
要将数据库中所有符合条件的数据求和,怎么操作?我用的adoconnection和TADOQuery两个控件?
Query1 = new TADOQuery(NULL);
Query1->Connection = Form1->ADOConnection1;
cmd = "select sum(Amount) from bank_trans where TrCode='1003'";
Query1->SQL->Clear();
Query1->SQL->Add( cmd );
try
{
Query1->Open();
}
catch(...)
{
s = "执行语句[" + cmd + "]失败";
Memo1->Lines->Add( s );
delete Query1;
return;
}
delete Query1;
s = "执行语句[" + cmd + "]成功";
到了这里就不知道怎么办了,查询成功了,如何取出结果的值呢?谢谢
[解决办法]
"select sum(Amount) AS SiBo from bank_trans where TrCode='1003'"
Query1->FieldByName("SiBo")->AsString