按条件sum用子查询啊
select x,(select sum(..) from y where ...)
group by ...

解决方案 »

  1.   

    to :  OpenVMS(半知半解) 
     
    select x,(select sum(..) from y where ...)
     group by ...中的(select sum(..) from y where ...) 只是得到月累计的全部产量
    而不是各个班次的月产量
      

  2.   

    select x,(select sum(..) from y where 班组=a.班组...)
    from y a
     group by ...
      

  3.   

    我觉得用最简单的
    select 组,sum(output * purity),sum(output)
    from 表
    where purity>0
    group by 组,月份
    就可以了
      

  4.   

    这几天在和那个Python互相折磨,都没顾上来,真不好意思。如果你的产量字段会有NULL值,可能会影响到统计结果,一定要当心。
      

  5.   

    说错了,是含硫量字段要特别当心,有可能会影响到你的Where判断