adoquery1中已有如下记录:
姓名     性别    年龄    
linjin   boy     26    
linlin   boy     25
chenjin  girl    20
lef      girl    22
hzh      boy     24
我想从adoquery1中计算出性别分别为boy和girl的记录数,该用什么SQL语句啊?

解决方案 »

  1.   

    select count(*) from table group by 性别
      

  2.   

    注意不是从表中计算,而是从adoquery1中计算
      

  3.   

    adoquery1.sql.add('select count(*) from table group by 性别');
    adoquery1.open
      

  4.   

    因为已经是返回的结果集了
    所以var
     bcount,gCount:integer;
    bcount:=0;
    gCount:=0;
    adoquery1.first;
    while not adoquery1.eof do
    begin
    if adoquery1['性别']='boy' then
     inc(bCount);
    if adoquery1['性别']='girl' then
     inc(gCount);
    adoquery1.next;
    end;