with ADOQuery1 do
begin
try 
       Close;
       First;
       SQL.Add('select count(*) as num from id_word_score where    word_score=''a''') ;
       Open;
       j :=fieldbyname('num').asinteger;
       Label1.Caption:=inttostr(j);
我想统计数据库第一条记录中的a的个数  请问上面的语句有什么错哦 ?   或者有什么方法能实现这样的结果  

解决方案 »

  1.   

    第一条记录中的a的个数?是记录中某一字段包含a字符串的个数还是 所有表中满足word_score等于a 的记录条数?
      

  2.   

    表第一条记录中word_score字段里面有好多个a
      

  3.   

    如果是后种,帮你把代码整理下: with adoquery1 do
       begin
          close;
          sql.clear;
          sql.add('select count(*) as num from id_word_score where  word_score=''a''');
          open;
       end;
       if adoquery1.recordcount>0 then
          label1.caption:=adoquery1.fieldbyname('num').asstring;
    end;
      

  4.   

    前一种啊,那这样吧
    function TForm1.rightpos(ch:char;str:string):integer;
    var
      i:integer;
    begin
      result:=0;
      for i:=0 to length(s) do
        if str[i]=ch then
           result:=result+1;
    end;procedure TForm1.Button1Click(Sender: TObject);
    var
      tmp:string;
    begin
       with adoquery1 do
       begin
          close;
          sql.clear;
          sql.add('select word_score from id_word_score ');
          open;
       end;
       if adoquery1.recordcount>0 then
         begin
           adoquery1.first; //记录集第一条
           tmp:=adoquery1.fieldbyname('word_score').asstring;
           Label1.Caption:=inttostr(rightpos('a',tmp)); //查找a的个数
        end
        else
           application.message('没有信息!','提示',mb_ok);
    end;
      

  5.   

    [Error] Real2.pas(49): E2003 Undeclared identifier: 'rightpos'
    出现这个提示 
      

  6.   

    汗一个。。
    你需要在你的程序代码
     private
        { Private declarations }
      public
        { Public declarations }这个部分上面加上  function rightpos(ch:char;str:string):integer; 这个函数在rightpos函数中for i:=0 to length(s) do
    改成length(str),自己写掉了,忘记改过来了.我都测试过了的,都没问题
      

  7.   

    他自己定义了一个rightpos在上面的了啊.你没有注意看啊.
      

  8.   

    我已经用了  功能也实现了  我现在想把得到的结果覆盖'word_score'里面的内容 应该能行吧