select int(item),sum(quantity) as quantity,sum(amount) as amount,description from details 
group by int(item),description //必须加上description
order by int(item)

解决方案 »

  1.   

    加了description后程序能运行了,但没有求和.程序如下:
    procedure TfrmPrintChoice.DetailsTotal;
    begin
    with adodtstReportTotal do
       begin
       close;
       commandText:='select int(item),sum(quantity) as quantity,sum(packnum) as  packnum,'
                     +'sum(amount) as amount,sum(gross) as gross,sum(net) as net,'
                     +'sum(meas) as meas,description from details where invoice_id='
                     + ''''+frmDocument.DBEdit1.text+''''
                     + 'group by int(item),description order by int(item)';
       open;
       end;
      

  2.   

    ''''+frmDocument.DBEdit1.text+''''
    这个是什么意思??要作什么??
      

  3.   

    符合条件invoice_id=''''+frmDocument.DBEdit1.text+''''的选出来,frmDocument.DBEdit1.text是字符.
      

  4.   

    首先去掉description进行调试,我不太明白你的description字段是什么东东;如果成功求和的话说明是它的问题,
    如果不行,把你的库结构贴出来看看.
      

  5.   

    group by 时必须把select中的非计算字段按分组顺序列出来,即:group by int(item),description .
    求和结果不对可能是因为先以int(item)分组,后以description分组的缘故.建议不要加上description了.鱼和熊掌不可得兼!!!!!!
      

  6.   


      也许是你的invoice_id取值出错了吧??  造成了没有返回结果集建议调试你的frmDocument.DBEdit1.text
      

  7.   

    a9a9a9():去掉description可以求和,问题是我要把description也选出来,他不是一个可计算的字段,加上去后就不求和了,有简单办法吗?
      

  8.   

    details的库结构:
    item float
    amount float
    quantity float
    packnum int
    gross float
    net float
    meas float
    invoice_id char
    description charitem    description    quantity    amount    gross   net   meas
    -----   -----------    --------    ------    -----   ----  ----
    1.0     SHOES 
    1.1     9021           3000        50000     300     280    5
    1.2     9022           5000           
      

  9.   

    details的库结构:
    item float
    amount float
    quantity float
    packnum int
    gross float
    net float
    meas float
    invoice_id char
    description char表details的数据为:
    item    description    quantity    amount    gross   net   meas
    -----   -----------    --------    ------    -----   ----  ----
    1.0     SHOES 
    1.1     9021           3000        50000     300     280    5
    1.2     9022           5000        80000     500     300    6
    2.0     HAT            
    2.1     8921           3000        50000     200     180    3
    2.2     8965           4000        60000     350     300    5我要的结果集为:
    item    description    quantity    amount    gross   net   meas
    -----   -----------    --------    ------    -----   ----  ----
    1.0     SHOES          8000        130000    800     580    11
    2.0     HAT            7000        110000    550     480     8 
      

  10.   

    表結構設計有問題.建議這樣設計:details的表结构:                 |
    Item  float
    amount float
    quantity float
    packnum int
    gross float
    net float
    meas float
    invoice_id char
    description char
    Type_id char              |Type的表结构:
    Type_id char
    Type    char表details的数据为:
    item    description    quantity    amount    gross  net  meas  Type_id
    -----  -----------    --------    ------    -----  ----  ----  -------
    1.1    9021          3000        50000    300    280    5        1
    1.2    9022          5000        80000    500    300    6        1
    2.1    8921          3000        50000    200    180    3        2
    2.2    8965          4000        60000    350    300    5        2表Type的数据为:
    Type_id        Type
    -------       ------
      1            SHOES
      2            HAT這樣查詢起來應該沒問題了吧
      

  11.   

    那你只能用复合查询了!比如把上面查出的结果作为一个结果集,再用item作为连接条件联上description.看看书吧(介绍SQL的书中都有这方面的介绍).不难的!!!!!!