sql.Add('select 供货单位编码,供货单位,sum(总金额) 统计金额 from 入库登记表 group by 供货单位编码 having 入库日期>=:rq1 and 入库日期<=:rq2 and 供货单位=:ghdw');
parameters.ParamByName('rq1').Value :=datetostr(rq1box.Date);
parameters.ParamByName('rq2').Value :=datetostr(rq2box.Date);
parameters.ParamByName('ghdw').Value :=trim(ghdwbox.Text);
错误在:列入库登记表.供货单位不是聚合函数,也不在group by 语句中。
这个查询是从入库登记表中查找某个供货单位在某个时期内的提供的货品的总金额,当然这个单位会供货几次,入库登记表都有记录

解决方案 »

  1.   

    类似的问题
    http://community.csdn.net/Expert/topic/4766/4766536.xml?temp=.5051691
      

  2.   

    sql.Add('select 供货单位编码,供货单位,sum(总金额) 统计金额 from 入库登记表 group by 供货单位编码,供货单位 having 入库日期>=:rq1 and 入库日期<=:rq2 and 供货单位=:ghdw');
    parameters.ParamByName('rq1').Value :=datetostr(rq1box.Date);
    parameters.ParamByName('rq2').Value :=datetostr(rq2box.Date);
    parameters.ParamByName('ghdw').Value :=trim(ghdwbox.Text);
    错误在:列入库登记表.供货单位不是聚合函数,也不在group by 语句中。
    这个查询是从入库登记表中查找某个供货单位在某个时期内的提供的货品的总金额,当然这个单位会供货几次,入库登记表都有记录
    ---在GROUP BY 中把“,供货单位”加进去就可以了
      

  3.   

    改成这样:
    sql.Add('select 供货单位编码,供货单位,sum(总金额) 统计金额 from 入库登记表 
    where 入库日期>=:rq1 and 入库日期<=:rq2 and 供货单位=:ghdw
    group by 供货单位编码,供货单位');Having后面是对合计字段的过滤,如having sum(总金额)>10000,只是对某一字段过滤,还是要用WHERE,而且放在GROUP前面
      

  4.   


    procedure Tghdwghjetjfm.FormCreate(Sender: TObject);
    begin
    ghdwbox.Clear ;
    bmedit.Clear;
    with adoquery1 do
    begin
    close;
    sql.Clear;
    sql.Add('select distinct 供货单位 from 入库登记表');
    open;
    first;
    while not eof do
    begin
    ghdwbox.Items.Add(fieldbyname('供货单位').AsString);
    next;
    end;
    end;
    {with adoquery1 do
    begin
    close;
    sql.Clear ;
    sql.Add('select * from 入库登记表');
    open;
    first;
    while not eof do
    begin
    ghdwbox.Items.Add(fieldbyname('供货单位').AsString);
    next;
    end;
    end; }
    with stringgrid1 do
    begin
    cells[1,0]:='供货单位编码';
    cells[2,0]:='供货单位';
    cells[3,0]:='供货总额';
    end;
    end;procedure Tghdwghjetjfm.cxbtClick(Sender: TObject);begin
    if (trim(ghdwbox.Text)='') or (trim(bmedit.Text)='') then
    begin
    showmessage('请选择供货单位!');
    exit;
    end;
    try
    with adoquery1 do
    begin
    close;
    sql.Clear ;
    sql.Add('select 供货单位编码,供货单位,sum(总金额) 统计金额 from 入库登记表 where 入库日期>=:rq1 and 入库日期<=:rq2 and 供货单位=:ghdw and 供货单位编码=:ghdwbm group by 供货单位编码,供货单位 ');
    parameters.ParamByName('rq1').Value :=datetostr(rq1box.Date);
    parameters.ParamByName('rq2').Value :=datetostr(rq2box.Date);
    parameters.ParamByName('ghdw').Value :=trim(ghdwbox.Text);
    parameters.ParamByName('ghdwbm').Value :=trim(bmedit.Text);
    open;if recordcount<>0 then
    with stringgrid1 do
    begin
    cells[1,1]:=fieldbyname('供货单位编码').AsString ;
    cells[2,1]:=fieldbyname('供货单位').AsString ;
    cells[3,1]:=fieldbyname('统计金额').AsString ;end;end;except
    showmessage('此供货单位在此日期之内没有供货!');
    end;
    end;整个查询如上,结果执行时,一点击查询按钮,整个窗体关闭,不知道错在哪里!高手好人做到底,help me!
      

  5.   

    Sql 语句中加入 :
    group by 供货单位编码,供货单位
      

  6.   

    你是不是用的delphi6,不要用with,我发觉delphi6中用with经常会在with包含里的语句执行到外面来了,估计就是你with里的close语句被理解成了窗体的关闭了。写成这样试试:
    adoquery1.close;
    with adoquery1 do
    begin
    sql.Clear ;
    ......