SELECT A,SUM(B)AS B,SUM(C)AS C,D FROM TABLE1 GROUP BY A,D
B,C要用整型,因为sum()是求和函数。

解决方案 »

  1.   

    这么简单呀,谢谢了!我太笨了就没想到在GROUP BY 后面加个D
      

  2.   

    select shiph.ordid as 合同编号,longname as 客户名称, ordh12 as 工程名称 ,sum(ordb.qty) as 合同签约方量 , sum(ph28) as 当月销货方量 , sum(ph19) as 当月销货进金额 
    from ordh,cust,shiph,ordb 
    where cust.custid=ordh.custid and ordh.ordid=shiph.ordid and ordb.ordid=shiph.ordid and shipdate between 20020926 and  20021025 
    order by shipdate
    group by shiph.ordid,longname,ordh12
    报错:Server: Msg 156, Level 15, State 1, Line 5
    Incorrect syntax near the keyword 'group'.
    这是为什么能帮忙吗?谢谢了
      

  3.   

    to cooket;
      把 order by 放在group by 后面!
      

  4.   

    select shiph.ordid as 合同编号,longname as 客户名称, ordh12 as 工程名称 ,sum(ordb.qty) as 合同签约方量 , sum(ph28) as 当月销货方量 , sum(ph19) as 当月销货进金额 
    from ordh,cust,shiph,ordb 
    where cust.custid=ordh.custid and ordh.ordid=shiph.ordid and ordb.ordid=shiph.ordid and shipdate between 20020926 and  20021025 
    order by shipdate
    group by shiph.ordid,longname,ordh12
    order by shipdate语法是对了,不够高效!