本帖最后由 yaotomo 于 2013-08-14 09:35:57 编辑

解决方案 »

  1.   


    sw_04字段是拣配单号,是字母和数字的组合,不可能sum
    count倒是可以,但是用count的话,就成了一个物料下所有c_sw04字段都为空才 sum(s.n_dryweight)
    我想实现的是,如果同一个物料下的一个记录的c_sw04为空,就sum上,如果不为空,就不往上加
      

  2.   


    sw_04字段是拣配单号,是字母和数字的组合,不可能sum
    count倒是可以,但是用count的话,就成了一个物料下所有c_sw04字段都为空才 sum(s.n_dryweight)
    我想实现的是,如果同一个物料下的一个记录的c_sw04为空,就sum上,如果不为空,就不往上加
    想到只能union
      

  3.   


    UNION的话,需要3分钟才能查出来,再和其他查询做连接
    整改查询需要10分钟左右。。我想用户是受不了的
      

  4.   

    稍作修改即可
    select  s.c_materialid 物料编码,
                   sum (case
                     when s.n_dryweight> 0 and s.c_sw04 is null then s.n_dryweight      
                     else
                      0 )
                   end 当日库存
              from AG_TP_STOCK s
              left join TB_MATERIELMAIN b
                on b.c_materielid = s.c_materialid
             where s.c_storageid = '20802079'
               and b.c_factoryid = '2080'
             group by s.c_materialid
      

  5.   

    不好意思,上面的应该有点问题select  s.c_materialid 物料编码,
                   sum (case
                     when s.n_dryweight> 0 and s.c_sw04 is null then s.n_dryweight      
                     else 0  end ) 当日库存
              from AG_TP_STOCK s
              left join TB_MATERIELMAIN b
                on b.c_materielid = s.c_materialid
             where s.c_storageid = '20802079'
               and b.c_factoryid = '2080'
             group by s.c_materialid
      

  6.   


    select  s.c_materialid 物料编码,
                   sum (case
                     when s.n_dryweight> 0 and s.c_sw04 is null then s.n_dryweight      
                     else
                      0 )
                   end 当日库存
              from AG_TP_STOCK s
    where s.c_storageid = '20802079'
    group by s.c_materialid请问不加外链接不行吗?
      

  7.   

    谢谢yinan9 ,真是救星啊!回8#朋友,不加不行的,很复杂的一个报表