SQL语句如下:
select gdsbs.prvid,gdsbs.gdsid,gds.gdsdes,gds.spc,gds.bsepkg,gdsbs.qty,gdsbs.prc,
gdsbs.amt FROM bizdep,gdsbs,gds WHERE ( bizdep.dptid = gdsbs.dptid ) and 
( bizdep.depid = gdsbs.depid ) and (gdsbs.fscprdid='1310') and 
(gdsbs.dptid like '%')  and (bizdep.savdptid like '602') and 
(gdsbs.prvid like '00500') and gdsbs.gdsid in 
(select gdsid from gds where clsid like '%%'+'%') and 
gdsbs.gdsid=gds.gdsid and qty <> 0 
order by gdsbs.prvid,gdsbs.gdsid desc
结果如下:
如何让让gdsbs.gdsid 字段相同的 ID 只显示1次 然后让qty 库存,amt金额  字段合计,还有字段合计。

解决方案 »

  1.   

    SELECT gdsbs.gdsid,SUM(gdsbs.qty),SUM(gdsbs.amt),后面自己补齐
    FROM (你上面的结果集 ) AS gdsbs
    GROUP BY gdsbs.gdsid
      

  2.   


    select gdsbs.prvid
    ,gdsbs.gdsid
    ,gds.gdsdes
    ,gds.spc
    ,gds.bsepkg
    ,SUM(gdsbs.qty) AS Qty
    ,gdsbs.prc
    ,SUM(gdsbs.amt) AS Amt
    FROM bizdep,gdsbs,gds
     WHERE ( bizdep.dptid = gdsbs.dptid ) 
     and ( bizdep.depid = gdsbs.depid ) 
     and (gdsbs.fscprdid='1310') 
     and (gdsbs.dptid like '%')  
    and (bizdep.savdptid like '602') and 
    (gdsbs.prvid like '00500') and gdsbs.gdsid in 
    (select gdsid from gds where clsid like '%%'+'%') and 
    gdsbs.gdsid=gds.gdsid and qty <> 0 
    GROUP BY gdsbs.prvid
    ,gdsbs.gdsid
    ,gds.gdsdes
    ,gds.spc
    ,gds.bsepkg
    ,gdsbs.prc
    order by gdsbs.prvid,gdsbs.gdsid desc
      

  3.   

    try this,select gdsbs.prvid,gdsbs.gdsid,gds.gdsdes,gds.spc,gds.bsepkg,
    sum(gdsbs.qty) 'qty',gdsbs.prc,sum(gdsbs.amt) 'amt'
    FROM bizdep,gdsbs,gds 
    WHERE bizdep.dptid = gdsbs.dptid and 
    bizdep.depid = gdsbs.depid and gdsbs.fscprdid='1310' and 
    gdsbs.dptid like '%' and bizdep.savdptid like '602' and 
    gdsbs.prvid like '00500' and gdsbs.gdsid in 
    (select gdsid from gds where clsid like '%%'+'%') and 
    gdsbs.gdsid=gds.gdsid and qty<>0
    group by gdsbs.prvid,gdsbs.gdsid,gds.gdsdes,gds.spc,gds.bsepkg,gdsbs.prc
    order by gdsbs.prvid,gdsbs.gdsid desc
      

  4.   

    要sum求和,只需要在你原来的语句后面加上group by就可以了哈:
    select gdsbs.prvid,
       gdsbs.gdsid,
       gds.gdsdes,
       gds.spc,
       gds.bsepkg,
       SUM(gdsbs.qty) AS Qty,
       gdsbs.prc,
       SUM(gdsbs.amt) AS Amt
       
    FROM bizdep,gdsbs,gds
    WHERE ( bizdep.dptid = gdsbs.dptid ) 
      and ( bizdep.depid = gdsbs.depid ) 
      and (gdsbs.fscprdid='1310') 
      and (gdsbs.dptid like '%')  
      and (bizdep.savdptid like '602') 
      and (gdsbs.prvid like '00500') 
      and gdsbs.gdsid in 
             (select gdsid from gds 
              where clsid like '%%'+'%') 
          and gdsbs.gdsid=gds.gdsid and qty <> 0 
    GROUP BY 
        gdsbs.prvid,
    gdsbs.gdsid,
    gds.gdsdes,
    gds.spc,
    gds.bsepkg,
    gdsbs.prc
    order by gdsbs.prvid,gdsbs.gdsid desc